Created
June 16, 2011 02:56
-
-
Save sgharms/1028581 to your computer and use it in GitHub Desktop.
Fun with metaprogramming in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
module Magic | |
def self.active_voice_indicative_mood_present_tense(spec) | |
puts "hey you called me, with an argument of #{spec}" | |
end | |
end | |
class Zabu | |
def razzle | |
puts "you have been razzled" | |
end | |
def method_missing(symbol, *args) | |
if symbol.to_s =~ /(.*tense)_(.*)/ | |
puts "method missing triggered for #{symbol.to_s} was called" | |
puts "First [#{$1}] and second [#{$2}]" | |
Magic.send($1.to_sym, $2).send($2) | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment