SlideShare a Scribd company logo
1 of 32
Download to read offline
Seven Languages in Seven Days: Ruby
            prepared by @zachleat
Creator
Yukihiro Matsumoto
“Matz”
Influences
Lisp, Smalltalk, Perl
Trade-offs
    Simplicity for Safety
Productivity for Performance
irb
Ruby’s Interactive Console
Syntax
WHEN U DECLARE VARS




U DECLARE WEAKNESS
                 Courage Wolf
RUBY CODE ROI




ALWAYS RETURN
  SOMETHING     Business Cat
Y U NO EVALUTE STRING?




   SINGLE QUOTES!!
   puts “hello, #{language}”
                               Y U NO?
>> puts ‘literal string’
literal string

>> subject = ‘world’
=> “world”

>> puts “hello, #{subject}”
hello, world




                       Y U NO?
HUMANS ARE CARBON




 RUBY IS OBJECTS
                   Philosoraptor
>> 4.class
=> FixNum

>> 4.methods
=> [“inspect”, “%”, “<<“, ...

>> false.class
=> FalseClass




                           Philosoraptor
MY CONDITIONALS



ALWAYS SUCCESSFUL
               Success Kid
>> x = 4
=> 4

>> puts ‘True!!’ if x == 4
True!!
=> nil

>> puts ‘True!!’ unless x == 4
=> nil

>> puts ‘True!!’ if not true
=> nil

>> puts ‘True!!’ if !true
=> nil
                               Success Kid
# Everything but nil and false
# evaluate to true. 0 is true!
>> puts “This is true” if 0
This is true
=> nil

# and, &&
# or, ||

# &, | are the non-short circuit
# equivalents




                             Success Kid
THE BEST LOOPS




ITERATE OVER THIRST
              The Most Interesting Man in the World
>>   x = x + 1 while x < 10
=>   nil
>>   x
=>   10

>>   x = x - 1 until x == 1
=>   nil
>>   x
=>   1




                      The Most Interesting Man in the World
KEYBOARD CAT
HAS NOTHING ON




 DUCK TYPINGTechnologically Impaired Duck
>> 4 + ‘four’
TypeError: String can’t be coerced
into Fixnum

# Strongly typed
# Dynamic: Checked at run time

>> a = [‘100’, 100.0]
=> [‘100’, 100.0]
>> while i < 2
>>   puts a[i].to_i
>>   i += 1
>> end
100
100
                        Technologically Impaired Duck
FFFFFUUUUUUUUUU




UUUUUUUNCTIONS
              FFFUUUUUU
>> def tell_the_truth
>>     true
>> end

# Last expression is return value




                        Technologically Impaired Duck
ARRRRRRRAYS




AND HASHES
>> animals = [‘lions’, ‘tigers’]
=> [‘lions’, ‘tigers’]

>> numbers = {1 => ‘one’, 2 =>
‘two’}
=> {1=>”one”, 2=>”two”}

# Symbols
>>   ‘string’.object_id
=>   3092010
>>   ‘string’.object_id
=>   3089690
>>   :string.object_id
=>   69618
>>   :string.object_id
=>   69618
>> def winning(options = {})
>>   if(options[:profession] == :gambler)
>>     true
>>   else
>>     false
>>   end
>> end
=> nil

>> winning
=> false

# {} optional for last parameter
>> winning(:profession => :lawyer)
=> true
YO DAWG I HEARD YOU
  LIKED CODE BLOCKS



SO YOU COULD RUN CODE
     IN YOUR CODE
>> 3.times { puts ‘hi’ }
hi
hi
hi

>> animals = [‘lions’, ‘tigers’]
>> animals.each {|a| puts a}
lions
tigers

# Blocks can be passed as
parameters
>> def pass_block(&block)
>> end
>> pass_block { puts ‘hi’ }
Classes
class MyClass
  def initialize(name)
    @name = name # instance var
    @@other = ‘’ # class var
  end

  def name
    return @name
  end

  # methods that check end in ?
end

my_class = MyClass.new(‘Name’)
my_class.name # returns ‘Name’
Modules
module MyModule
  def name
    return @name
  end
end

class MyClass
  include MyModule

  def initialize(name)
    @name = name
  end
end

my_class = MyClass.new(‘Name’)
my_class.name # returns ‘Name’
Enumerable
# Implements each method




Comparable
# Implements <=> (spaceship) method
Open Classes
# First invocation defines
# Second invocation modifies

class NilClass
  def blank?
    true
  end
end

class String
  def blank?
    self.size == 0
  end
end

[‘’, ‘person’, nil].each {|a| puts a unless a.blank?}
# outputs person
method_missing

More Related Content

Similar to Seven Languages in Seven Days: Ruby

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
 
Beautiful python - PyLadies
Beautiful python - PyLadiesBeautiful python - PyLadies
Beautiful python - PyLadiesAlicia Pérez
 
Python WATs: Uncovering Odd Behavior
Python WATs: Uncovering Odd BehaviorPython WATs: Uncovering Odd Behavior
Python WATs: Uncovering Odd BehaviorAmy Hanlon
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosEdgar Suarez
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Wen-Tien Chang
 
RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby Gautam Rege
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to RubyRyan Cross
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a bossgsterndale
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 

Similar to Seven Languages in Seven Days: Ruby (20)

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)
 
7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
 
Ruby
RubyRuby
Ruby
 
Beautiful python - PyLadies
Beautiful python - PyLadiesBeautiful python - PyLadies
Beautiful python - PyLadies
 
Python WATs: Uncovering Odd Behavior
Python WATs: Uncovering Odd BehaviorPython WATs: Uncovering Odd Behavior
Python WATs: Uncovering Odd Behavior
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Python! An Introduction
Python! An IntroductionPython! An Introduction
Python! An Introduction
 
Ruby Intro {spection}
Ruby Intro {spection}Ruby Intro {spection}
Ruby Intro {spection}
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a boss
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Values
ValuesValues
Values
 
Python Workshop
Python  Workshop Python  Workshop
Python Workshop
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 

Recently uploaded

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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Recently uploaded (20)

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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

Seven Languages in Seven Days: Ruby

  • 1. Seven Languages in Seven Days: Ruby prepared by @zachleat
  • 2.
  • 5. Trade-offs Simplicity for Safety Productivity for Performance
  • 8. WHEN U DECLARE VARS U DECLARE WEAKNESS Courage Wolf
  • 9. RUBY CODE ROI ALWAYS RETURN SOMETHING Business Cat
  • 10. Y U NO EVALUTE STRING? SINGLE QUOTES!! puts “hello, #{language}” Y U NO?
  • 11. >> puts ‘literal string’ literal string >> subject = ‘world’ => “world” >> puts “hello, #{subject}” hello, world Y U NO?
  • 12. HUMANS ARE CARBON RUBY IS OBJECTS Philosoraptor
  • 13. >> 4.class => FixNum >> 4.methods => [“inspect”, “%”, “<<“, ... >> false.class => FalseClass Philosoraptor
  • 15. >> x = 4 => 4 >> puts ‘True!!’ if x == 4 True!! => nil >> puts ‘True!!’ unless x == 4 => nil >> puts ‘True!!’ if not true => nil >> puts ‘True!!’ if !true => nil Success Kid
  • 16. # Everything but nil and false # evaluate to true. 0 is true! >> puts “This is true” if 0 This is true => nil # and, && # or, || # &, | are the non-short circuit # equivalents Success Kid
  • 17. THE BEST LOOPS ITERATE OVER THIRST The Most Interesting Man in the World
  • 18. >> x = x + 1 while x < 10 => nil >> x => 10 >> x = x - 1 until x == 1 => nil >> x => 1 The Most Interesting Man in the World
  • 19. KEYBOARD CAT HAS NOTHING ON DUCK TYPINGTechnologically Impaired Duck
  • 20. >> 4 + ‘four’ TypeError: String can’t be coerced into Fixnum # Strongly typed # Dynamic: Checked at run time >> a = [‘100’, 100.0] => [‘100’, 100.0] >> while i < 2 >> puts a[i].to_i >> i += 1 >> end 100 100 Technologically Impaired Duck
  • 22. >> def tell_the_truth >> true >> end # Last expression is return value Technologically Impaired Duck
  • 24. >> animals = [‘lions’, ‘tigers’] => [‘lions’, ‘tigers’] >> numbers = {1 => ‘one’, 2 => ‘two’} => {1=>”one”, 2=>”two”} # Symbols >> ‘string’.object_id => 3092010 >> ‘string’.object_id => 3089690 >> :string.object_id => 69618 >> :string.object_id => 69618
  • 25. >> def winning(options = {}) >> if(options[:profession] == :gambler) >> true >> else >> false >> end >> end => nil >> winning => false # {} optional for last parameter >> winning(:profession => :lawyer) => true
  • 26. YO DAWG I HEARD YOU LIKED CODE BLOCKS SO YOU COULD RUN CODE IN YOUR CODE
  • 27. >> 3.times { puts ‘hi’ } hi hi hi >> animals = [‘lions’, ‘tigers’] >> animals.each {|a| puts a} lions tigers # Blocks can be passed as parameters >> def pass_block(&block) >> end >> pass_block { puts ‘hi’ }
  • 28. Classes class MyClass def initialize(name) @name = name # instance var @@other = ‘’ # class var end def name return @name end # methods that check end in ? end my_class = MyClass.new(‘Name’) my_class.name # returns ‘Name’
  • 29. Modules module MyModule def name return @name end end class MyClass include MyModule def initialize(name) @name = name end end my_class = MyClass.new(‘Name’) my_class.name # returns ‘Name’
  • 30. Enumerable # Implements each method Comparable # Implements <=> (spaceship) method
  • 31. Open Classes # First invocation defines # Second invocation modifies class NilClass def blank? true end end class String def blank? self.size == 0 end end [‘’, ‘person’, nil].each {|a| puts a unless a.blank?} # outputs person