Your SlideShare is downloading. ×
Ruby's method_missing
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Ruby's method_missing

1,359
views

Published on

Just two slides on method_missing

Just two slides on method_missing


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,359
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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