SlideShare a Scribd company logo
1 of 51
Download to read 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(:+)}}

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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
 

Similar to 名古屋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
 

Similar to 名古屋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
 

More from 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
 

More from 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
 

Recently uploaded

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 

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