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

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Kürzlich hochgeladen (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

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