Skip to content

Instantly share code, notes, and snippets.

@seanhandley
Created October 10, 2010 20:51
Show Gist options
  • Save seanhandley/619554 to your computer and use it in GitHub Desktop.
Save seanhandley/619554 to your computer and use it in GitHub Desktop.
class Object
def method_missing(symbol, *args, &block)
if(args.nil?)
symbol.to_s
else
"#{symbol.to_s} #{args[0].to_s}"
end
end
end
puts "the quick brown fox jumps over the lazy dog"
puts the quick brown fox jumps over the lazy dog
# Outputs:
# >> the quick brown fox jumps over the lazy dog
# >> the quick brown fox jumps over the lazy dog
@raldred
Copy link

raldred commented Oct 10, 2010

This is basic stuff really. Watch Meta programming by Dave Thomas for some even cooler stuff.

@seanhandley
Copy link
Author

I've had his screencast series on metaprogramming for ages now. Very cool stuff indeed. This is a simple example from the Ruby class we've been doing at OTB, posted mainly for the benefit of the non Ruby programmers following :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment