SlideShare a Scribd company logo
1 of 48
Corey Haines, Journeyman Developer




                                                       Ruby
                                                         It really is Love




Saturday, May 30, 2009
About




Saturday, May 30, 2009
Not About


                         Convincing You To Use Ruby




Saturday, May 30, 2009
About


                         Things I love in Ruby
                                         duck-typing
                                        open classes
                         (almost) everything is executable ruby code




Saturday, May 30, 2009
Should You Learn Ruby?




Saturday, May 30, 2009
Corey Haines
                             Journeyman
                              Developer

                          That’s Me!




                            www.coreyhaines.com

                           coreyhaines@gmail.com

Saturday, May 30, 2009
On To Ruby




Saturday, May 30, 2009
“...trying to make Ruby
                         natural, not simple.”
                                - Yukihiro Matsumoto
                                                        “Matz”




                                    image courtesy Jim Lindley on flickr




Saturday, May 30, 2009
Qualities


                          Simple Syntax
                         Object-Oriented
                           Duck-Typing
                             Blocks
                          Open Classes


Saturday, May 30, 2009
Qualities


                          Simple Syntax
                         Object-Oriented
                           Duck-Typing
                             Blocks
                          Open Classes


Saturday, May 30, 2009
Initializers



                 arr = [1, 6, 2, 3, 5]

                 arr2 = [“Element”, “Another one”]

                 lookup = { :ruby => “love”,
                            :c_sharp => “good too”,
                            :python => “cool” }




Saturday, May 30, 2009
Classes
                 class Rectangle
                  attr_accessor :width, :height

                    def initialize(width, height)
                     self.width = width
                     self.height = height
                    end

                  def area
                   width * height
                  end
                 end




Saturday, May 30, 2009
>> r = Rectangle.new(5, 20)
               => #<Rectangle:0x3691d8 @width=5, @height=20>
               >> r.area
               => 100




Saturday, May 30, 2009
Qualities


                          Simple Syntax
                         Object-Oriented
                           Duck-Typing
                             Blocks
                          Open Classes


Saturday, May 30, 2009
Everything is an object


                         >> 9.succ
                         => 10
                         >> 9.nil?
                         => false
                         >> 9.between? 8, 10
                         => true
                         >> 9.class
                         => Fixnum




Saturday, May 30, 2009
No Really

                         >> 9.succ
                         => 10
                         >> 9.nil?
                         => false
                         >> 9.between? 8, 10
                         => true                    Wha?
                         >> 9.class
                         => Fixnum
                         >> Fixnum.class
                         => Class




Saturday, May 30, 2009
Ever written something like this?


             public void MakeItQuack<T>(T quacker)
             where T : ICanQuack
             {
               quacker.Quack();
             }




Saturday, May 30, 2009
Really Wanted



           public void MakeItQuack<T>(T quacker)
           where T can quack
           {
             quacker.quack();
           }




Saturday, May 30, 2009
Qualities


                          Simple Syntax
                         Object-Oriented
                           Duck-Typing
                             Blocks
                          Open Classes


Saturday, May 30, 2009
No, not that kind




Saturday, May 30, 2009
Duck-Typing




                                   Walks like a duck
                                   Quacks like a duck
                                   Must be a duck?




Saturday, May 30, 2009
Well, no



                         But, we can interact with it like a duck!


                         And Pretend!




Saturday, May 30, 2009
def make_it_quack(quacker)
                          quacker.quack();
                         end




Saturday, May 30, 2009
Type != Class




                         Behavior/Interaction-Orientation




Saturday, May 30, 2009
Qualities


                          Simple Syntax
                         Object-Oriented
                           Duck-Typing
                             Blocks
                          Open Classes


Saturday, May 30, 2009
Blocks

                         a = [5, 7, 10, 24]

                         a.each do |num|
                          puts num
                         end

                         b = a.map do |num|
                          num * 2
                         end

                         puts b.inspect




Saturday, May 30, 2009
Accepting Blocks

                   def five_times
                    yield 1
                    yield 2
                    yield 3
                    yield 4
                    yield 5
                   end

                   five_times do |num|
                     puts num
                   end




Saturday, May 30, 2009
Accepting Blocks

         def five_times(&block)
          block.call(1)
          block.call(2)
          block.call(3)
          block.call(4)
          block.call(5)
         end

         five_times do |num|
           puts num
         end




Saturday, May 30, 2009
Qualities


                          Simple Syntax
                         Object-Oriented
                           Duck-Typing
                             Blocks
                          Open Classes


Saturday, May 30, 2009
Open Classes




                         Say goodbye to sealed/virtual/override/argh




Saturday, May 30, 2009
def convert(to_convert)
               return nil if to_convert.nil?
               return to_convert if to_convert.empty?
               do_conversion(to_convert)
             end




Saturday, May 30, 2009
As You Wish




                         class NilClass
                            def empty?
                              true
                            end
                         end




Saturday, May 30, 2009
def convert(to_convert)
                           return to_convert if to_convert.empty?
                           do_conversion(to_convert)
                         end




Saturday, May 30, 2009
Setting Time




                         current_time = 17




Saturday, May 30, 2009
write the code you wish you had


                                 current_time = 5.pm




Saturday, May 30, 2009
Then get it working



                            class Fixnum
                             def pm
                              self + 12
                             end
                            end




Saturday, May 30, 2009
Type != Class (redux)




                         a = “coreyhaines@gmail.com;me@coreyhaines.com”




Saturday, May 30, 2009
Type != Class (redux redux)

                         a = “coreyhaines@gmail.com;me@coreyhaines.com”
                         a.extend(EmailAddressList)


                         puts a.email_addresses.inspect


                         a.each_address do |address|
                         Mailer.send_email_to(address)
                         end




Saturday, May 30, 2009
Remember

                         With great power comes great responsibility




Saturday, May 30, 2009
Qualities


                          Simple Syntax
                         Object-Oriented
                           Duck-Typing
                             Blocks
                          Open Classes


Saturday, May 30, 2009
Qualities

                         Awesomeness!
                             Simple Syntax
                            Object-Oriented
                              Duck-Typing
                                Blocks
                             Open Classes


Saturday, May 30, 2009
Method Missing




Saturday, May 30, 2009
Examples




                         Builder




Saturday, May 30, 2009
Mixins




Saturday, May 30, 2009
Type != Class




Saturday, May 30, 2009
Examples




                         Email Addresses




Saturday, May 30, 2009
defining methods




Saturday, May 30, 2009
Examples




                         Email Addresses




Saturday, May 30, 2009

More Related Content

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
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...
 
+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...
 
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...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.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...
 
"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 ...
 
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, ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Featured

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
 
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)
 

Featured (20)

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
 
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
 
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
 
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
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
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
 
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)
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Intro To Ruby

  • 1. Corey Haines, Journeyman Developer Ruby It really is Love Saturday, May 30, 2009
  • 3. Not About Convincing You To Use Ruby Saturday, May 30, 2009
  • 4. About Things I love in Ruby duck-typing open classes (almost) everything is executable ruby code Saturday, May 30, 2009
  • 5. Should You Learn Ruby? Saturday, May 30, 2009
  • 6. Corey Haines Journeyman Developer That’s Me! www.coreyhaines.com coreyhaines@gmail.com Saturday, May 30, 2009
  • 7. On To Ruby Saturday, May 30, 2009
  • 8. “...trying to make Ruby natural, not simple.” - Yukihiro Matsumoto “Matz” image courtesy Jim Lindley on flickr Saturday, May 30, 2009
  • 9. Qualities Simple Syntax Object-Oriented Duck-Typing Blocks Open Classes Saturday, May 30, 2009
  • 10. Qualities Simple Syntax Object-Oriented Duck-Typing Blocks Open Classes Saturday, May 30, 2009
  • 11. Initializers arr = [1, 6, 2, 3, 5] arr2 = [“Element”, “Another one”] lookup = { :ruby => “love”, :c_sharp => “good too”, :python => “cool” } Saturday, May 30, 2009
  • 12. Classes class Rectangle attr_accessor :width, :height def initialize(width, height) self.width = width self.height = height end def area width * height end end Saturday, May 30, 2009
  • 13. >> r = Rectangle.new(5, 20) => #<Rectangle:0x3691d8 @width=5, @height=20> >> r.area => 100 Saturday, May 30, 2009
  • 14. Qualities Simple Syntax Object-Oriented Duck-Typing Blocks Open Classes Saturday, May 30, 2009
  • 15. Everything is an object >> 9.succ => 10 >> 9.nil? => false >> 9.between? 8, 10 => true >> 9.class => Fixnum Saturday, May 30, 2009
  • 16. No Really >> 9.succ => 10 >> 9.nil? => false >> 9.between? 8, 10 => true Wha? >> 9.class => Fixnum >> Fixnum.class => Class Saturday, May 30, 2009
  • 17. Ever written something like this? public void MakeItQuack<T>(T quacker) where T : ICanQuack { quacker.Quack(); } Saturday, May 30, 2009
  • 18. Really Wanted public void MakeItQuack<T>(T quacker) where T can quack { quacker.quack(); } Saturday, May 30, 2009
  • 19. Qualities Simple Syntax Object-Oriented Duck-Typing Blocks Open Classes Saturday, May 30, 2009
  • 20. No, not that kind Saturday, May 30, 2009
  • 21. Duck-Typing Walks like a duck Quacks like a duck Must be a duck? Saturday, May 30, 2009
  • 22. Well, no But, we can interact with it like a duck! And Pretend! Saturday, May 30, 2009
  • 23. def make_it_quack(quacker) quacker.quack(); end Saturday, May 30, 2009
  • 24. Type != Class Behavior/Interaction-Orientation Saturday, May 30, 2009
  • 25. Qualities Simple Syntax Object-Oriented Duck-Typing Blocks Open Classes Saturday, May 30, 2009
  • 26. Blocks a = [5, 7, 10, 24] a.each do |num| puts num end b = a.map do |num| num * 2 end puts b.inspect Saturday, May 30, 2009
  • 27. Accepting Blocks def five_times yield 1 yield 2 yield 3 yield 4 yield 5 end five_times do |num| puts num end Saturday, May 30, 2009
  • 28. Accepting Blocks def five_times(&block) block.call(1) block.call(2) block.call(3) block.call(4) block.call(5) end five_times do |num| puts num end Saturday, May 30, 2009
  • 29. Qualities Simple Syntax Object-Oriented Duck-Typing Blocks Open Classes Saturday, May 30, 2009
  • 30. Open Classes Say goodbye to sealed/virtual/override/argh Saturday, May 30, 2009
  • 31. def convert(to_convert) return nil if to_convert.nil? return to_convert if to_convert.empty? do_conversion(to_convert) end Saturday, May 30, 2009
  • 32. As You Wish class NilClass def empty? true end end Saturday, May 30, 2009
  • 33. def convert(to_convert) return to_convert if to_convert.empty? do_conversion(to_convert) end Saturday, May 30, 2009
  • 34. Setting Time current_time = 17 Saturday, May 30, 2009
  • 35. write the code you wish you had current_time = 5.pm Saturday, May 30, 2009
  • 36. Then get it working class Fixnum def pm self + 12 end end Saturday, May 30, 2009
  • 37. Type != Class (redux) a = “coreyhaines@gmail.com;me@coreyhaines.com” Saturday, May 30, 2009
  • 38. Type != Class (redux redux) a = “coreyhaines@gmail.com;me@coreyhaines.com” a.extend(EmailAddressList) puts a.email_addresses.inspect a.each_address do |address| Mailer.send_email_to(address) end Saturday, May 30, 2009
  • 39. Remember With great power comes great responsibility Saturday, May 30, 2009
  • 40. Qualities Simple Syntax Object-Oriented Duck-Typing Blocks Open Classes Saturday, May 30, 2009
  • 41. Qualities Awesomeness! Simple Syntax Object-Oriented Duck-Typing Blocks Open Classes Saturday, May 30, 2009
  • 43. Examples Builder Saturday, May 30, 2009
  • 45. Type != Class Saturday, May 30, 2009
  • 46. Examples Email Addresses Saturday, May 30, 2009
  • 48. Examples Email Addresses Saturday, May 30, 2009