SlideShare a Scribd company logo
method_missing When you send a message to a Ruby object, Ruby looks for a method to invoke with the same name as the message you sent.  You can override method_missing and tell Ruby what to do when it can’t find a method. Developers often use this to create domain-specific languages (DSLs) in Ruby.
class Thing   def method_missing(m, *args, &block)       puts "There's no method called #{m} here -- please try again."       puts "parameters = #{args.inspect}"   end   end   >> t = Thing.new >> t.anything("ddd",3) There's no method called anything here -- please try again. parameters = ["ddd", 3] => nil

More Related Content

What's hot

C++ unit-1-part-9
C++ unit-1-part-9C++ unit-1-part-9
C++ unit-1-part-9
Jadavsejal
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
Volodymyr Byno
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA Polymorphism
Mahi Mca
 
Generics
GenericsGenerics
Generics
adil raja
 
Thinking Like a Programmer
Thinking Like a ProgrammerThinking Like a Programmer
Thinking Like a Programmer
Cate Huston
 
Smali语法
Smali语法Smali语法
Smali语法
xiaoshan8743
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
Robbin Zhao
 
Ruby Hell Yeah
Ruby Hell YeahRuby Hell Yeah
Ruby Hell Yeah
Anupom Syam
 
C++ unit-2-part-3
C++ unit-2-part-3C++ unit-2-part-3
C++ unit-2-part-3
Jadavsejal
 
learn Ruby in AMC Square learning
learn Ruby in AMC Square learninglearn Ruby in AMC Square learning
learn Ruby in AMC Square learningASIT Education
 
datatypes_variables_constants
datatypes_variables_constantsdatatypes_variables_constants
datatypes_variables_constants
Micheal Ogundero
 
Sharable of qualities of clean code
Sharable of qualities of clean codeSharable of qualities of clean code
Sharable of qualities of clean code
Eman Mohamed
 
c# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventionsc# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventions
Micheal Ogundero
 
Method in oop
Method in oopMethod in oop
Method in oop
Nadimozzaman Pappo
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
Suraj Bora
 
Access Modifiers in C# ,Inheritance and Encapsulation
Access Modifiers in C# ,Inheritance and EncapsulationAccess Modifiers in C# ,Inheritance and Encapsulation
Access Modifiers in C# ,Inheritance and Encapsulation
Abid Kohistani
 
Custom Tags
Custom TagsCustom Tags
Custom Tags
cfjedimaster
 

What's hot (20)

C++ unit-1-part-9
C++ unit-1-part-9C++ unit-1-part-9
C++ unit-1-part-9
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA Polymorphism
 
Generics
GenericsGenerics
Generics
 
SE Michigan PowerShell Users Group - Regex Part1
SE Michigan PowerShell Users Group -  Regex Part1SE Michigan PowerShell Users Group -  Regex Part1
SE Michigan PowerShell Users Group - Regex Part1
 
Thinking Like a Programmer
Thinking Like a ProgrammerThinking Like a Programmer
Thinking Like a Programmer
 
Smali语法
Smali语法Smali语法
Smali语法
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
 
05 ruby classes
05 ruby classes05 ruby classes
05 ruby classes
 
Ruby Hell Yeah
Ruby Hell YeahRuby Hell Yeah
Ruby Hell Yeah
 
Interfaces
InterfacesInterfaces
Interfaces
 
C++ unit-2-part-3
C++ unit-2-part-3C++ unit-2-part-3
C++ unit-2-part-3
 
learn Ruby in AMC Square learning
learn Ruby in AMC Square learninglearn Ruby in AMC Square learning
learn Ruby in AMC Square learning
 
datatypes_variables_constants
datatypes_variables_constantsdatatypes_variables_constants
datatypes_variables_constants
 
Sharable of qualities of clean code
Sharable of qualities of clean codeSharable of qualities of clean code
Sharable of qualities of clean code
 
c# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventionsc# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventions
 
Method in oop
Method in oopMethod in oop
Method in oop
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
 
Access Modifiers in C# ,Inheritance and Encapsulation
Access Modifiers in C# ,Inheritance and EncapsulationAccess Modifiers in C# ,Inheritance and Encapsulation
Access Modifiers in C# ,Inheritance and Encapsulation
 
Custom Tags
Custom TagsCustom Tags
Custom Tags
 

More from Sarah Allen

Internet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequencesInternet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequences
Sarah Allen
 
RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)
Sarah Allen
 
Communication is a Technical Skill
Communication is a Technical SkillCommunication is a Technical Skill
Communication is a Technical Skill
Sarah Allen
 
Improving Federal Government Services
Improving Federal Government ServicesImproving Federal Government Services
Improving Federal Government Services
Sarah Allen
 
Transparency Wins
Transparency WinsTransparency Wins
Transparency Wins
Sarah Allen
 
A Short History of Computers
A Short History of ComputersA Short History of Computers
A Short History of Computers
Sarah Allen
 
Making Software Fun
Making Software FunMaking Software Fun
Making Software Fun
Sarah Allen
 
Power of Transparency
Power of TransparencyPower of Transparency
Power of Transparency
Sarah Allen
 
Designing for Fun
Designing for FunDesigning for Fun
Designing for Fun
Sarah Allen
 
Ruby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World ConferenceRuby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World Conference
Sarah Allen
 
Identities of Dead People
Identities of Dead PeopleIdentities of Dead People
Identities of Dead People
Sarah Allen
 
Let's pretend
Let's pretendLet's pretend
Let's pretend
Sarah Allen
 
3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby 3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby
Sarah Allen
 
Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?
Sarah Allen
 
Why no ruby in gov?
Why no ruby in gov?Why no ruby in gov?
Why no ruby in gov?
Sarah Allen
 
People Patterns or What I learned from Toastmasters
People Patterns or What I learned from ToastmastersPeople Patterns or What I learned from Toastmasters
People Patterns or What I learned from Toastmasters
Sarah Allen
 
Blazing Cloud: Agile Product Development
Blazing Cloud: Agile Product DevelopmentBlazing Cloud: Agile Product Development
Blazing Cloud: Agile Product Development
Sarah Allen
 
Crowdsourced Transcription Landscape
Crowdsourced Transcription LandscapeCrowdsourced Transcription Landscape
Crowdsourced Transcription Landscape
Sarah Allen
 
Lessons Learned Future Thoughts
Lessons Learned Future ThoughtsLessons Learned Future Thoughts
Lessons Learned Future Thoughts
Sarah Allen
 
Mobile Web Video
Mobile Web VideoMobile Web Video
Mobile Web Video
Sarah Allen
 

More from Sarah Allen (20)

Internet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequencesInternet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequences
 
RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)
 
Communication is a Technical Skill
Communication is a Technical SkillCommunication is a Technical Skill
Communication is a Technical Skill
 
Improving Federal Government Services
Improving Federal Government ServicesImproving Federal Government Services
Improving Federal Government Services
 
Transparency Wins
Transparency WinsTransparency Wins
Transparency Wins
 
A Short History of Computers
A Short History of ComputersA Short History of Computers
A Short History of Computers
 
Making Software Fun
Making Software FunMaking Software Fun
Making Software Fun
 
Power of Transparency
Power of TransparencyPower of Transparency
Power of Transparency
 
Designing for Fun
Designing for FunDesigning for Fun
Designing for Fun
 
Ruby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World ConferenceRuby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World Conference
 
Identities of Dead People
Identities of Dead PeopleIdentities of Dead People
Identities of Dead People
 
Let's pretend
Let's pretendLet's pretend
Let's pretend
 
3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby 3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby
 
Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?
 
Why no ruby in gov?
Why no ruby in gov?Why no ruby in gov?
Why no ruby in gov?
 
People Patterns or What I learned from Toastmasters
People Patterns or What I learned from ToastmastersPeople Patterns or What I learned from Toastmasters
People Patterns or What I learned from Toastmasters
 
Blazing Cloud: Agile Product Development
Blazing Cloud: Agile Product DevelopmentBlazing Cloud: Agile Product Development
Blazing Cloud: Agile Product Development
 
Crowdsourced Transcription Landscape
Crowdsourced Transcription LandscapeCrowdsourced Transcription Landscape
Crowdsourced Transcription Landscape
 
Lessons Learned Future Thoughts
Lessons Learned Future ThoughtsLessons Learned Future Thoughts
Lessons Learned Future Thoughts
 
Mobile Web Video
Mobile Web VideoMobile Web Video
Mobile Web Video
 

Ruby's method_missing

  • 1. method_missing When you send a message to a Ruby object, Ruby looks for a method to invoke with the same name as the message you sent. You can override method_missing and tell Ruby what to do when it can’t find a method. Developers often use this to create domain-specific languages (DSLs) in Ruby.
  • 2. class Thing def method_missing(m, *args, &block) puts "There's no method called #{m} here -- please try again." puts "parameters = #{args.inspect}" end end >> t = Thing.new >> t.anything("ddd",3) There's no method called anything here -- please try again. parameters = ["ddd", 3] => nil