際際滷

際際滷Share a Scribd company logo
Ruby on Arrays
2012/4/25 yoyogi.rb
檎顎恢霞の塘双について
徭失B初

フリ`エンジニア

twitter:@nysalor
blog: http://blog.larus.jp/
挫きなメソッドはArrayEnumerable#map
塘双


Arrayクラスで協x

[]でくくる

勣殆は採でもいい
塘双の箭


[1, 2, 3, 4, 5]
[:alpha, :bravo, :charlie]
[1, `second¨, :third, [4.1, 4.2, 4.3], { :?fth => `element¨}]
塘双の恬り圭
塘双の恬り圭

腎の塘双
塘双の恬り圭

腎の塘双


a = []
a = Array.new
塘双の恬り圭
塘双の恬り圭

嶄附の秘った塘双
塘双の恬り圭

嶄附の秘った塘双


a = [1, 3, 5, 7]
a = Array.new(3, 5) #=> [5, 5, 5]
塘双の恬り圭
塘双の恬り圭

猟忖双から恬撹
塘双の恬り圭

猟忖双から恬撹


a = %w(tinker tailor soldier spy)
a = ^battle ship:light cruiser:destroyer ̄.split(^: ̄)
塘双の恬り圭
塘双の恬り圭

to_aメソッド
塘双の恬り圭

to_aメソッド

a = (1..3).to_a
a = (^a ̄.. ̄z ̄).to_a
a = {^alpha ̄ => ^A ̄, ^bravo ̄ => ^B ̄}.to_a
塘双の恬り圭

to_aメソッド
            賺殍穽

a = (1..3).to_a
a = (^a ̄.. ̄z ̄).to_a
a = {^alpha ̄ => ^A ̄, ^bravo ̄ => ^B ̄}.to_a
勣殆の函り竃し
勣殆の函り竃し

a = ["alpha", "bravo", "charlie"]
勣殆の函り竃し

a = ["alpha", "bravo", "charlie"]



 a[2] #=> ^charlie ̄
 a[0, 3] #=> ^alpha ̄, ^bravo ̄, ^charlie ̄
勣殆の函り竃し
勣殆の函り竃し

a = ["alpha", "bravo", "charlie"]
勣殆の函り竃し

a = ["alpha", "bravo", "charlie"]


 a.?rst #=> ^alpha ̄
 a.last #=> ^charlie ̄
 a.shift #=> ^alpha ̄
 a.pop #=> ^charlie ̄
勣殆の函り竃し

a = ["alpha", "bravo", "charlie"]


 a.?rst #=> ^alpha ̄
 a.last #=> ^charlie ̄
 a.shift #=> ^alpha ̄    勣殆が茅される

 a.pop #=> ^charlie ̄
勣殆の函り竃し

a = ["alpha", "bravo", "charlie"]


 a.?rst #=> ^alpha ̄
 a.last #=> ^charlie ̄
 a.shift #=> ^alpha ̄    勣殆が茅される

 a.pop #=> ^charlie ̄    勣殆が茅される
勣殆の弖紗
勣殆の弖紗

a = ["alpha", "bravo", "charlie"]
勣殆の弖紗

a = ["alpha", "bravo", "charlie"]


 a << ^delta ̄
 a.push(^delta ̄)
 a.unshift(^zulu ̄)
塘双の處麻
塘双の處麻

a = ["alpha", "bravo", "charlie"]
b = ["charlie", "delta", "echo"]
塘双の處麻

a = ["alpha", "bravo", "charlie"]
b = ["charlie", "delta", "echo"]


 a+b
 a-b
 a*3
塘双の處麻
塘双の處麻

a = ["alpha", "bravo", "charlie"]
b = ["charlie", "delta", "echo"]
塘双の處麻

a = ["alpha", "bravo", "charlie"]
b = ["charlie", "delta", "echo"]


 a & b #=> [^charlie ̄]
 a|b
 a == b #=> false
塘双の荷恬
塘双の荷恬

a = ["alpha", "bravo", "charlie"]
塘双の荷恬

a = ["alpha", "bravo", "charlie"]



 a.reverse
 a.shuf?e
塘双の荷恬
塘双の荷恬

a = ["alpha", "bravo", "charlie"]
b = ["delta", "echo", "foxtrot"]
c = [b, a]
塘双の荷恬

a = ["alpha", "bravo", "charlie"]
b = ["delta", "echo", "foxtrot"]
c = [b, a]



 c.?atten
 c.?atten.sort
塘双の荷恬
塘双の荷恬

a = ["golf", nil, nil]
b = ["hotel", "hotel", "india"]
塘双の荷恬

a = ["golf", nil, nil]
b = ["hotel", "hotel", "india"]




 a.compact
 b.uniq
篤乙張瓮愁奪
篤乙張瓮愁奪

a   =   ["alpha", "bravo", "charlie"]
b   =   ["charlie", "delta", "echo"]
c   =   [b, a]
d   =   c.flatten
篤乙張瓮愁奪

a = ["alpha", "bravo", "charlie"]
b = ["charlie", "delta", "echo"]
c = [b, a]
d a.reverse
   = c.flatten

 a.reverse!
 a.shuf?e!
 c.?atten!
 d.sort!
篤乙張瓮愁奪
篤乙張瓮愁奪

e = ["golf", nil, nil]
f = ["hotel", "hotel", "india"]
篤乙張瓮愁奪

e = ["golf", nil, nil]
f = ["hotel", "hotel", "india"]




 a.compact!
 b.uniq!
篤乙張瓮愁奪
篤乙張瓮愁奪

a = ["alpha", "bravo", "charlie"]
篤乙張瓮愁奪

a = ["alpha", "bravo", "charlie"]


 a.shift
 a.pop
 a.unshift(^zulu ̄)
 a.push(^golf ̄)
 a.clear
篤乙張瓮愁奪

a = ["alpha", "bravo", "charlie"]


 a.shift
 a.pop
 a.unshift(^zulu ̄)   これらは!がなくても篤乙


 a.push(^golf ̄)
 a.clear
猟忖双晒
猟忖双晒

a = ["alpha", "bravo", "charlie"]
b = ["charlie", "delta", "echo"]
猟忖双晒

a = ["alpha", "bravo", "charlie"]
b = ["charlie", "delta", "echo"]



 a.join #=> ^alphabravocharlie ̄
 a.join(^/ ̄) #=> ^alpha/bravo/charlie ̄
塘双の得
塘双の得

a = ["alpha", "bravo", "charlie"]
塘双の得

a = ["alpha", "bravo", "charlie"]




 a.include?(^bravo ̄) #=> true
 a.all? #=> true
塘双の得
塘双の得

a = ["alpha", "bravo", "charlie"]
塘双の得

a = ["alpha", "bravo", "charlie"]




 a.size #=> 3
 a.count #=> 3
 a.length #=> 3
塘双の得
塘双の得

g = ["juliet", nil, nil]
h = [nil, nil, nil]
塘双の得

g = ["juliet", nil, nil]
h = [nil, nil, nil]



 g.all? #=> false
 g.any? #=> true
 h.any? #=> false
塘双の碧
塘双の碧

a = ["alpha", "bravo", "charlie"]
塘双の碧

a = ["alpha", "bravo", "charlie"]



 a.?nd(/l/).?rst
 a.grep(/a/)
イテレ`ション
イテレ`ション
a = ["alpha", "bravo", "charlie"]

a.each do |x|
  p x
end
イテレ`ション
a = ["alpha", "bravo", "charlie"]

a.each do |x|   ブロック篳
  p x
end
イテレ`ション
イテレ`ション

a = ["alpha", "bravo", "charlie"]

a.each_with_index do |x, idx|
  p x
  p idx
end
イテレ`ション
イテレ`ション
a = ["alpha", "bravo", "charlie"]

a.inject(0) do |result, x|
  result + x.size
end
イテレ`ション
a = ["alpha", "bravo", "charlie"]
         兜豚
a.inject(0) do |result, x|
  result + x.size
end
イテレ`ション
イテレ`ション
a = ["alpha", "bravo", "charlie"]

a.map do |x|
  x.reverse
end
イテレ`ション
イテレ`ション
a = ["alpha", "bravo", "charlie"]

a.map! do |x|
  x.reverse
end
イテレ`ション
a = ["alpha", "bravo", "charlie"]

a.map! do |x|   篤乙張瓮愁奪
  x.reverse
end
まとめ


塘双は安が侮い

篤乙張瓮愁奪匹没吭

イテレ`ション
嵎夘鬴
嵎夘鬴

if available?
??Question.all.map(&:answer!)
end
ご賠ありがとうございました

More Related Content

Featured (20)

2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
?
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design ProcessStorytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
?
Artificial Intelligence, Data and Competition C SCHREPEL C June 2024 OECD dis...
Artificial Intelligence, Data and Competition C SCHREPEL C June 2024 OECD dis...Artificial Intelligence, Data and Competition C SCHREPEL C June 2024 OECD dis...
Artificial Intelligence, Data and Competition C SCHREPEL C June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
?
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
?
2024 State of Marketing Report C by Hubspot
2024 State of Marketing Report C by Hubspot2024 State of Marketing Report C by Hubspot
2024 State of Marketing Report C by Hubspot
Marius Sescu
?
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
?
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
?
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
?
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
?
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
?
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
?
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
?
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
?
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
?
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
?
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
?
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
?
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
?
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
?
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
?
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
?
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design ProcessStorytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
?
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
?
2024 State of Marketing Report C by Hubspot
2024 State of Marketing Report C by Hubspot2024 State of Marketing Report C by Hubspot
2024 State of Marketing Report C by Hubspot
Marius Sescu
?
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
?
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
?
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
?
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
?
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
?
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
?
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
?
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
?
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
?
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
?
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
?
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
?

Ruby on

Editor's Notes