Your SlideShare is downloading. ×
0
Ruby's method_missing
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,383

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,383
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
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<br />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. <br />You can override method_missing and tell Ruby what to do when it can’t find a method.<br />Developers often use this to create domain-specific languages (DSLs) in Ruby.<br />
  • 2. class Thing<br /> def method_missing(m, *args, &amp;block) <br /> puts &quot;There&apos;s no method called #{m} here -- please try again.&quot; <br /> puts &quot;parameters = #{args.inspect}&quot;<br /> end <br />end <br />&gt;&gt; t = Thing.new<br />&gt;&gt; t.anything(&quot;ddd&quot;,3)<br />There&apos;s no method called anything here -- please try again.<br />parameters = [&quot;ddd&quot;, 3]<br />=&gt; nil<br />

×