SlideShare a Scribd company logo
1 of 29
Inside Enumerable ,[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object]
What is it? ,[object Object],[object Object],[object Object]
hash = { :a  => 1,  :b  => 2} hash.collect  do  |key, value|  value * 4 end [4,8] [4,8,12] [4,8,12] array = [1,2,3] array.collect  do  |value| value * 4 end range = 1..3 range.collect  do  |value| value * 4 end
hash = { :a  => 1,  :b  => 2} hash.collect  do  |key, value|  value * 4 end array = [1,2,3] array.collect  do  |value| value * 4 end range = 1..3 range.collect  do  |value| value * 4 end module  Enumerable def  collect ... end end
multiple inheritance
mixins
Mixins Cannot be instantiated Can be mixed in
Mixins usually  donā€™t stand alone donā€™t stand alone ,[object Object],[object Object],[object Object],[object Object],[object Object]
Enumerable requires each() [1,2,3].collect {|i| i*2} [2,4,6]
Enumerable.collect class  Foo include  Enumerable def  each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end module  Enumerable def  collect array = [] each do |a| array <<  yield (a) end array end end
Enumerable.collect module  Enumerable def  collect array = [] each do |a| array <<  yield (a) end array end end class  Foo include  Enumerable def  each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end
Enumerable.collect module  Enumerable def  collect array = [] each do |a| array <<  yield (a) end array end end class  Foo include  Enumerable def  each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end
Enumerable.collect class  Foo include  Enumerable def  each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end module  Enumerable def  collect array = [] each do |a| array <<  yield (a) end array end end
Enumerable.collect module  Enumerable def  collect array = [] each do |a| array <<  yield (a) end array end end class  Foo include  Enumerable def  each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end
Enumerable.collect class  Foo include  Enumerable def  each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end module  Enumerable def  collect array = [] each do |a| array <<  yield (a) end array end end Result [2,4,6]
Required methods ,[object Object],[object Object],[object Object],[object Object],Comparison operator
Enumerable methods all?, any?, collect, detect, each_cons, each_slice, each_with_index, entries, enum_cons, enum_slice, enum_with_index, find, find_all, grep, include?, inject, map, max, member?, min, partition, reject, select, sort, sort_by, to_a, to_set, zip
any? [1,2,3,4].any? {|a| a > 2} Returns true if this block... ...returns true for  any of these values
all? [1,2,3,4].all? {|a| a > 2} Returns true if this block... ...returns true for  ALL of these values
collect, map ,[object Object],[object Object],[1,2,3].collect {|i| i*2} [2,4,6]
find, detect ,[object Object],[object Object],[object Object]
find_all, select ,[object Object],[object Object],[object Object]
grep ,[object Object],[object Object],Case equality
Case equality ,[object Object],Case equality Regular equality
Case equality case myvar when 1..50 # do something when 51 # do something when /^+$/ # do something end Within the range This exact number Matches this regular expression Different kind of equality as a convenience in case statements
Case equality in grep [1,2,3].grep(1..50) [1,2,3].grep(51) [1,2,3].grep(/^+$/) Within the range This exact number Matches this regular expression
Wrap up ,[object Object],[object Object],[object Object]
Shameless Plug ,[object Object],[object Object]

More Related Content

What's hot (20)

List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
Ā 
2.4 multiplication of real numbers 1
2.4 multiplication of real numbers 12.4 multiplication of real numbers 1
2.4 multiplication of real numbers 1
Ā 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
Ā 
C# Arrays
C# ArraysC# Arrays
C# Arrays
Ā 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
Ā 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
Ā 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
Ā 
Higher Order Procedures (in Ruby)
Higher Order Procedures (in Ruby)Higher Order Procedures (in Ruby)
Higher Order Procedures (in Ruby)
Ā 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
Ā 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
Ā 
Python
PythonPython
Python
Ā 
Numerical analysisgroup19
Numerical analysisgroup19Numerical analysisgroup19
Numerical analysisgroup19
Ā 
Python PCEP Loops
Python PCEP LoopsPython PCEP Loops
Python PCEP Loops
Ā 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
Ā 
Arrays C#
Arrays C#Arrays C#
Arrays C#
Ā 
Python numbers
Python numbersPython numbers
Python numbers
Ā 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ā 
Slicing in Python - What is It?
Slicing in Python - What is It?Slicing in Python - What is It?
Slicing in Python - What is It?
Ā 
Pytho_tuples
Pytho_tuplesPytho_tuples
Pytho_tuples
Ā 
Day2
Day2Day2
Day2
Ā 

Similar to Inside Enumerable

Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Rubyerockendude
Ā 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Rubyerockendude
Ā 
Puppet Language 4.0 - PuppetConf 2014
Puppet Language 4.0 - PuppetConf 2014Puppet Language 4.0 - PuppetConf 2014
Puppet Language 4.0 - PuppetConf 2014Puppet
Ā 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptxMURADSANJOUM
Ā 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0tutorialsruby
Ā 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0tutorialsruby
Ā 
Data structures Lecture 5
Data structures Lecture 5Data structures Lecture 5
Data structures Lecture 5AzharIqbal710687
Ā 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
Ā 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
Ā 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdfSpam92
Ā 
Twig tips and tricks
Twig tips and tricksTwig tips and tricks
Twig tips and tricksJavier Eguiluz
Ā 
Functional ruby
Functional rubyFunctional ruby
Functional rubyKerry Buckley
Ā 
Question 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfQuestion 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfanandhomeneeds
Ā 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfankit11134
Ā 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)Ishin Vin
Ā 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionarySoba Arjun
Ā 
Groovy Refactoring Patterns
Groovy Refactoring PatternsGroovy Refactoring Patterns
Groovy Refactoring PatternsNaresha K
Ā 

Similar to Inside Enumerable (20)

Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
Ā 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
Ā 
Recursion Lecture in Java
Recursion Lecture in JavaRecursion Lecture in Java
Recursion Lecture in Java
Ā 
Puppet Language 4.0 - PuppetConf 2014
Puppet Language 4.0 - PuppetConf 2014Puppet Language 4.0 - PuppetConf 2014
Puppet Language 4.0 - PuppetConf 2014
Ā 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptx
Ā 
F# array searching
F#  array searchingF#  array searching
F# array searching
Ā 
Ruby basics
Ruby basicsRuby basics
Ruby basics
Ā 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
Ā 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
Ā 
Data structures Lecture 5
Data structures Lecture 5Data structures Lecture 5
Data structures Lecture 5
Ā 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
Ā 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Ā 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdf
Ā 
Twig tips and tricks
Twig tips and tricksTwig tips and tricks
Twig tips and tricks
Ā 
Functional ruby
Functional rubyFunctional ruby
Functional ruby
Ā 
Question 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfQuestion 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdf
Ā 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
Ā 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
Ā 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Ā 
Groovy Refactoring Patterns
Groovy Refactoring PatternsGroovy Refactoring Patterns
Groovy Refactoring Patterns
Ā 

More from Mike Bowler

Retrospective Magic - Toronto Agile Conference
Retrospective Magic - Toronto Agile ConferenceRetrospective Magic - Toronto Agile Conference
Retrospective Magic - Toronto Agile ConferenceMike Bowler
Ā 
Retrospective science
Retrospective scienceRetrospective science
Retrospective scienceMike Bowler
Ā 
Brain Talk: More effective conversations through clean language
Brain Talk: More effective conversations through clean languageBrain Talk: More effective conversations through clean language
Brain Talk: More effective conversations through clean languageMike Bowler
Ā 
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14Mike Bowler
Ā 
Continuous Delivery for Agile Teams
Continuous Delivery for Agile TeamsContinuous Delivery for Agile Teams
Continuous Delivery for Agile TeamsMike Bowler
Ā 
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...Mike Bowler
Ā 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
Ā 

More from Mike Bowler (8)

Retrospective Magic - Toronto Agile Conference
Retrospective Magic - Toronto Agile ConferenceRetrospective Magic - Toronto Agile Conference
Retrospective Magic - Toronto Agile Conference
Ā 
Retrospective science
Retrospective scienceRetrospective science
Retrospective science
Ā 
Brain Talk: More effective conversations through clean language
Brain Talk: More effective conversations through clean languageBrain Talk: More effective conversations through clean language
Brain Talk: More effective conversations through clean language
Ā 
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Continuous Delivery: Responding to Change Faster Than Ever Before - SDEC14
Ā 
Continuous Delivery for Agile Teams
Continuous Delivery for Agile TeamsContinuous Delivery for Agile Teams
Continuous Delivery for Agile Teams
Ā 
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Exploring the magic behind dynamic finders: diving into ActiveRecord::Base.me...
Ā 
Date Once
Date OnceDate Once
Date Once
Ā 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
Ā 

Recently uploaded

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
Ā 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
Ā 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
Ā 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
Ā 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
Ā 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
Ā 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
Ā 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
Ā 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
Ā 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
Ā 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
Ā 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
Ā 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
Ā 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
Ā 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
Ā 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
Ā 
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
Ā 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
Ā 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
Ā 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
Ā 

Recently uploaded (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
Ā 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
Ā 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
Ā 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Ā 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
Ā 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
Ā 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Ā 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
Ā 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
Ā 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
Ā 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Ā 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
Ā 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Ā 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Ā 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
Ā 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
Ā 
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
Ā 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
Ā 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
Ā 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
Ā 

Inside Enumerable

  • 1.
  • 2.
  • 3.
  • 4. hash = { :a => 1, :b => 2} hash.collect do |key, value| value * 4 end [4,8] [4,8,12] [4,8,12] array = [1,2,3] array.collect do |value| value * 4 end range = 1..3 range.collect do |value| value * 4 end
  • 5. hash = { :a => 1, :b => 2} hash.collect do |key, value| value * 4 end array = [1,2,3] array.collect do |value| value * 4 end range = 1..3 range.collect do |value| value * 4 end module Enumerable def collect ... end end
  • 8. Mixins Cannot be instantiated Can be mixed in
  • 9.
  • 10. Enumerable requires each() [1,2,3].collect {|i| i*2} [2,4,6]
  • 11. Enumerable.collect class Foo include Enumerable def each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end module Enumerable def collect array = [] each do |a| array << yield (a) end array end end
  • 12. Enumerable.collect module Enumerable def collect array = [] each do |a| array << yield (a) end array end end class Foo include Enumerable def each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end
  • 13. Enumerable.collect module Enumerable def collect array = [] each do |a| array << yield (a) end array end end class Foo include Enumerable def each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end
  • 14. Enumerable.collect class Foo include Enumerable def each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end module Enumerable def collect array = [] each do |a| array << yield (a) end array end end
  • 15. Enumerable.collect module Enumerable def collect array = [] each do |a| array << yield (a) end array end end class Foo include Enumerable def each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end
  • 16. Enumerable.collect class Foo include Enumerable def each yield 1 yield 2 yield 3 end end Foo.new.collect do |num| num * 2 end module Enumerable def collect array = [] each do |a| array << yield (a) end array end end Result [2,4,6]
  • 17.
  • 18. Enumerable methods all?, any?, collect, detect, each_cons, each_slice, each_with_index, entries, enum_cons, enum_slice, enum_with_index, find, find_all, grep, include?, inject, map, max, member?, min, partition, reject, select, sort, sort_by, to_a, to_set, zip
  • 19. any? [1,2,3,4].any? {|a| a > 2} Returns true if this block... ...returns true for any of these values
  • 20. all? [1,2,3,4].all? {|a| a > 2} Returns true if this block... ...returns true for ALL of these values
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. Case equality case myvar when 1..50 # do something when 51 # do something when /^+$/ # do something end Within the range This exact number Matches this regular expression Different kind of equality as a convenience in case statements
  • 27. Case equality in grep [1,2,3].grep(1..50) [1,2,3].grep(51) [1,2,3].grep(/^+$/) Within the range This exact number Matches this regular expression
  • 28.
  • 29.