SlideShare uma empresa Scribd logo
1 de 51
Baixar para ler offline
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(:+)}}

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 名古屋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
 

Semelhante a 名古屋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
 

Mais de 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
 

Mais de 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
 

Último

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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
🐬 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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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 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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Último (20)

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...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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 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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

名古屋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(:+)}}