SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Downloaden Sie, um offline zu lesen
require 'win32ole'

app = WIN32OLE.new('Excel.Application')
book = app.Workbooks.Open(app.GetOpenFilename)

for row in book.ActiveSheet.UsedRange.Rows do
 for cell in row.Columns do
   p cell.Name
   p cell.Age
 end
end

book.close(false)
app.quit

    via http://jp.rubyist.net/magazine/?0027-ExcellentRuby
require "yaml"

people = []
for row in book.ActiveSheet.UsedRange.Rows
do
 for cell in row.Columns do
   people << {:name => cell.Name, :age =>
cell.Age}
 end
end

File.open 'people.yml', 'w' do |file|
 YAML.dump(people, file)
end
require 'yaml'

people = YAML.load_file 'people.yml'
people.each do |person|
 p = Person.new person
 p.save
end

       import.rb


ruby script/runner import.rb
u='           '
u.encoding # => #<Encoding:UTF-8>




s = u.encode(‘Shift_JIS’)
s.encoding # => #<Encoding:Shift_JIS>
# Ruby 1.9
"            "[0..2] # => "     "

# Ruby 1.8
"            "[0..2] # => "343201214"
$ cat hello.rb
p"                    "

$ ruby1.9 hello.rb
hello.rb:1: invalid multibyte char
(US-ASCII)
$ cat hello.rb
# vim:fileencoding=utf-8
p"                  "

$ ruby1.9 hello.rb
"                  "
vim
# vim:fileencoding=utf-8

emacs
# -*- coding: utf-8 -*-
[1, 2, 3].combination(2).to_a
# => [[1, 2], [1, 3], [2, 3]]


[1, 2, 3].permutation(2).to_a
# => [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1],
[3, 2]]
[1, 2].product([3, 4])
# => [[1, 3], [1, 4], [2, 3], [2, 4]]

flatten


[1, [2, [3]]].flatten(1) # => [1, 2, [3]]
# Ruby 1.8
# => [1, 2, 3]
[0, 1, 2, 3].shuffle # => [1, 3, 0, 2]
[0, 1, 2, 3].shuffle # => [2, 0, 3, 1]



[0, 1, 2, 3].sample    # => 2
[0, 1, 2, 3].sample(2) # => [3, 2]
[0, 1, 2, 3].take(2) # => [0, 1]


[0, 1, 2, 3].drop(1) # => [1, 2, 3]
# Ruby 1.8
[1,2,3,4,5].inject(0) {|result, i| result + i} # => 15

# 1.9
[1,2,3,4,5].inject(:+) # => 15
#            reduce          alias
[1,2,3,4,5].reduce(:+) # => 15
2                                                                 w

       data = (1..100).map{rand(5)+1}.map{|id| {:id => id, :value => rand(10000)}}
(1..5).map{|i| {:id => i, :sum => data.select{|h| h[:id] == i}.map{|h| h[:value]}.reduce(:+)}}

Weitere ähnliche Inhalte

Was ist angesagt?

Pro bun-fighting - Working with JavaScript projects
Pro bun-fighting - Working with JavaScript projectsPro bun-fighting - Working with JavaScript projects
Pro bun-fighting - Working with JavaScript projectsFrances Berriman
 
Functional testing with capybara
Functional testing with capybaraFunctional testing with capybara
Functional testing with capybarakoffeinfrei
 
Embracing Capybara
Embracing CapybaraEmbracing Capybara
Embracing CapybaraTim Moore
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for DeveloperNHN FORWARD
 
Creating Beautiful, Accessible, and User-Friendly Forms
Creating Beautiful, Accessible, and User-Friendly FormsCreating Beautiful, Accessible, and User-Friendly Forms
Creating Beautiful, Accessible, and User-Friendly FormsClarissa Peterson
 
The Secret Life of Forms
The Secret Life of FormsThe Secret Life of Forms
The Secret Life of FormsIvan Wilson
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilNova Patch
 

Was ist angesagt? (7)

Pro bun-fighting - Working with JavaScript projects
Pro bun-fighting - Working with JavaScript projectsPro bun-fighting - Working with JavaScript projects
Pro bun-fighting - Working with JavaScript projects
 
Functional testing with capybara
Functional testing with capybaraFunctional testing with capybara
Functional testing with capybara
 
Embracing Capybara
Embracing CapybaraEmbracing Capybara
Embracing Capybara
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
 
Creating Beautiful, Accessible, and User-Friendly Forms
Creating Beautiful, Accessible, and User-Friendly FormsCreating Beautiful, Accessible, and User-Friendly Forms
Creating Beautiful, Accessible, and User-Friendly Forms
 
The Secret Life of Forms
The Secret Life of FormsThe Secret Life of Forms
The Secret Life of Forms
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
 

Andere mochten auch

OSCNagoya 2011「App inventor入門」
OSCNagoya 2011「App inventor入門」OSCNagoya 2011「App inventor入門」
OSCNagoya 2011「App inventor入門」Shoya Tsukada
 
2080 1 yoga-rev1_2002_portugues
2080 1 yoga-rev1_2002_portugues2080 1 yoga-rev1_2002_portugues
2080 1 yoga-rev1_2002_portuguesSara
 
Catalogo Daisy´s Miniatures
Catalogo Daisy´s MiniaturesCatalogo Daisy´s Miniatures
Catalogo Daisy´s Miniaturesdaisyminiatures
 
Dtv, survey paper
Dtv, survey paperDtv, survey paper
Dtv, survey paperJose Ortiz
 
MULTISCALE MODELLING OF URBAN CLIMATE
MULTISCALE MODELLING OF URBAN CLIMATE MULTISCALE MODELLING OF URBAN CLIMATE
MULTISCALE MODELLING OF URBAN CLIMATE epfl
 
Cwe2010 paper 172
Cwe2010 paper 172Cwe2010 paper 172
Cwe2010 paper 172epfl
 

Andere mochten auch (7)

OSCNagoya 2011「App inventor入門」
OSCNagoya 2011「App inventor入門」OSCNagoya 2011「App inventor入門」
OSCNagoya 2011「App inventor入門」
 
2080 1 yoga-rev1_2002_portugues
2080 1 yoga-rev1_2002_portugues2080 1 yoga-rev1_2002_portugues
2080 1 yoga-rev1_2002_portugues
 
Airbus a380 details 9939393
Airbus a380 details 9939393Airbus a380 details 9939393
Airbus a380 details 9939393
 
Catalogo Daisy´s Miniatures
Catalogo Daisy´s MiniaturesCatalogo Daisy´s Miniatures
Catalogo Daisy´s Miniatures
 
Dtv, survey paper
Dtv, survey paperDtv, survey paper
Dtv, survey paper
 
MULTISCALE MODELLING OF URBAN CLIMATE
MULTISCALE MODELLING OF URBAN CLIMATE MULTISCALE MODELLING OF URBAN CLIMATE
MULTISCALE MODELLING OF URBAN CLIMATE
 
Cwe2010 paper 172
Cwe2010 paper 172Cwe2010 paper 172
Cwe2010 paper 172
 

Ähnlich wie 名古屋Ruby会議01 - Rubyでライフハッキング10連発♪

Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdfzehiwot hone
 
Elixir pattern matching and recursion
Elixir pattern matching and recursionElixir pattern matching and recursion
Elixir pattern matching and recursionBob Firestone
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosEdgar Suarez
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In RubyRoss Lawley
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worldsChristopher Spring
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubyJason Yeo Jie Shun
 
Ruby19 osdc-090418222718-phpapp02
Ruby19 osdc-090418222718-phpapp02Ruby19 osdc-090418222718-phpapp02
Ruby19 osdc-090418222718-phpapp02Apoorvi Kapoor
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015qmmr
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPaweł Dawczak
 
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)Kerry Buckley
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Cody Engel
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School ProgrammersSiva Arunachalam
 
PERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsPERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsSunil Kumar Gunasekaran
 

Ähnlich wie 名古屋Ruby会議01 - Rubyでライフハッキング10連発♪ (20)

Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdf
 
Elixir pattern matching and recursion
Elixir pattern matching and recursionElixir pattern matching and recursion
Elixir pattern matching and recursion
 
Into Clojure
Into ClojureInto Clojure
Into Clojure
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
 
Ruby19 osdc-090418222718-phpapp02
Ruby19 osdc-090418222718-phpapp02Ruby19 osdc-090418222718-phpapp02
Ruby19 osdc-090418222718-phpapp02
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)
 
Elixir
ElixirElixir
Elixir
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
 
Ken20150417
Ken20150417Ken20150417
Ken20150417
 
PERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsPERL for QA - Important Commands and applications
PERL for QA - Important Commands and applications
 
Ruby2.0でlazyな n-Queen
Ruby2.0でlazyな n-QueenRuby2.0でlazyな n-Queen
Ruby2.0でlazyな n-Queen
 

Mehr von Shoya Tsukada

Google I/O 2013に行ったついでにラスベガス戦果報告
Google I/O 2013に行ったついでにラスベガス戦果報告Google I/O 2013に行ったついでにラスベガス戦果報告
Google I/O 2013に行ったついでにラスベガス戦果報告Shoya Tsukada
 
高専カンファレンス in 岐阜 基調講演2 @gabu
高専カンファレンス in 岐阜 基調講演2 @gabu高専カンファレンス in 岐阜 基調講演2 @gabu
高専カンファレンス in 岐阜 基調講演2 @gabuShoya Tsukada
 
NGK2011B 昼の部 スマートフォンアプリ 開発とコミュニティと 勉強会と
NGK2011B 昼の部 スマートフォンアプリ 開発とコミュニティと 勉強会とNGK2011B 昼の部 スマートフォンアプリ 開発とコミュニティと 勉強会と
NGK2011B 昼の部 スマートフォンアプリ 開発とコミュニティと 勉強会とShoya Tsukada
 
「Camelog」Android開発秘話
「Camelog」Android開発秘話「Camelog」Android開発秘話
「Camelog」Android開発秘話Shoya Tsukada
 
ABC 2011 Summer App Inventor入門ワークショップ
ABC 2011 Summer App Inventor入門ワークショップABC 2011 Summer App Inventor入門ワークショップ
ABC 2011 Summer App Inventor入門ワークショップShoya Tsukada
 
ABC2011S コミュニティトラック デ部+つ部(江川崇&がぶ) つ部プレゼンツ「いま名古屋が暑い!」
ABC2011S コミュニティトラック デ部+つ部(江川崇&がぶ) つ部プレゼンツ「いま名古屋が暑い!」ABC2011S コミュニティトラック デ部+つ部(江川崇&がぶ) つ部プレゼンツ「いま名古屋が暑い!」
ABC2011S コミュニティトラック デ部+つ部(江川崇&がぶ) つ部プレゼンツ「いま名古屋が暑い!」Shoya Tsukada
 
ARお絵描きツール「Feel Sketch」 at Gadget1
ARお絵描きツール「Feel Sketch」 at Gadget1ARお絵描きツール「Feel Sketch」 at Gadget1
ARお絵描きツール「Feel Sketch」 at Gadget1Shoya Tsukada
 

Mehr von Shoya Tsukada (7)

Google I/O 2013に行ったついでにラスベガス戦果報告
Google I/O 2013に行ったついでにラスベガス戦果報告Google I/O 2013に行ったついでにラスベガス戦果報告
Google I/O 2013に行ったついでにラスベガス戦果報告
 
高専カンファレンス in 岐阜 基調講演2 @gabu
高専カンファレンス in 岐阜 基調講演2 @gabu高専カンファレンス in 岐阜 基調講演2 @gabu
高専カンファレンス in 岐阜 基調講演2 @gabu
 
NGK2011B 昼の部 スマートフォンアプリ 開発とコミュニティと 勉強会と
NGK2011B 昼の部 スマートフォンアプリ 開発とコミュニティと 勉強会とNGK2011B 昼の部 スマートフォンアプリ 開発とコミュニティと 勉強会と
NGK2011B 昼の部 スマートフォンアプリ 開発とコミュニティと 勉強会と
 
「Camelog」Android開発秘話
「Camelog」Android開発秘話「Camelog」Android開発秘話
「Camelog」Android開発秘話
 
ABC 2011 Summer App Inventor入門ワークショップ
ABC 2011 Summer App Inventor入門ワークショップABC 2011 Summer App Inventor入門ワークショップ
ABC 2011 Summer App Inventor入門ワークショップ
 
ABC2011S コミュニティトラック デ部+つ部(江川崇&がぶ) つ部プレゼンツ「いま名古屋が暑い!」
ABC2011S コミュニティトラック デ部+つ部(江川崇&がぶ) つ部プレゼンツ「いま名古屋が暑い!」ABC2011S コミュニティトラック デ部+つ部(江川崇&がぶ) つ部プレゼンツ「いま名古屋が暑い!」
ABC2011S コミュニティトラック デ部+つ部(江川崇&がぶ) つ部プレゼンツ「いま名古屋が暑い!」
 
ARお絵描きツール「Feel Sketch」 at Gadget1
ARお絵描きツール「Feel Sketch」 at Gadget1ARお絵描きツール「Feel Sketch」 at Gadget1
ARお絵描きツール「Feel Sketch」 at Gadget1
 

Kürzlich hochgeladen

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Kürzlich hochgeladen (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

名古屋Ruby会議01 - Rubyでライフハッキング10連発♪

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. require 'win32ole' app = WIN32OLE.new('Excel.Application') book = app.Workbooks.Open(app.GetOpenFilename) for row in book.ActiveSheet.UsedRange.Rows do for cell in row.Columns do p cell.Name p cell.Age end end book.close(false) app.quit via http://jp.rubyist.net/magazine/?0027-ExcellentRuby
  • 8. require "yaml" people = [] for row in book.ActiveSheet.UsedRange.Rows do for cell in row.Columns do people << {:name => cell.Name, :age => cell.Age} end end File.open 'people.yml', 'w' do |file| YAML.dump(people, file) end
  • 9. require 'yaml' people = YAML.load_file 'people.yml' people.each do |person| p = Person.new person p.save end import.rb ruby script/runner import.rb
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23. u=' ' u.encoding # => #<Encoding:UTF-8> s = u.encode(‘Shift_JIS’) s.encoding # => #<Encoding:Shift_JIS>
  • 24. # Ruby 1.9 " "[0..2] # => " " # Ruby 1.8 " "[0..2] # => "343201214"
  • 25. $ cat hello.rb p" " $ ruby1.9 hello.rb hello.rb:1: invalid multibyte char (US-ASCII)
  • 26. $ cat hello.rb # vim:fileencoding=utf-8 p" " $ ruby1.9 hello.rb " "
  • 28.
  • 29.
  • 30.
  • 31. [1, 2, 3].combination(2).to_a # => [[1, 2], [1, 3], [2, 3]] [1, 2, 3].permutation(2).to_a # => [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
  • 32. [1, 2].product([3, 4]) # => [[1, 3], [1, 4], [2, 3], [2, 4]] flatten [1, [2, [3]]].flatten(1) # => [1, 2, [3]] # Ruby 1.8 # => [1, 2, 3]
  • 33. [0, 1, 2, 3].shuffle # => [1, 3, 0, 2] [0, 1, 2, 3].shuffle # => [2, 0, 3, 1] [0, 1, 2, 3].sample # => 2 [0, 1, 2, 3].sample(2) # => [3, 2]
  • 34. [0, 1, 2, 3].take(2) # => [0, 1] [0, 1, 2, 3].drop(1) # => [1, 2, 3]
  • 35. # Ruby 1.8 [1,2,3,4,5].inject(0) {|result, i| result + i} # => 15 # 1.9 [1,2,3,4,5].inject(:+) # => 15 # reduce alias [1,2,3,4,5].reduce(:+) # => 15
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51. 2 w data = (1..100).map{rand(5)+1}.map{|id| {:id => id, :value => rand(10000)}} (1..5).map{|i| {:id => i, :sum => data.select{|h| h[:id] == i}.map{|h| h[:value]}.reduce(:+)}}