Skip to content

Instantly share code, notes, and snippets.

@sgharms
Created June 16, 2011 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgharms/1028581 to your computer and use it in GitHub Desktop.
Save sgharms/1028581 to your computer and use it in GitHub Desktop.
Fun with metaprogramming in Ruby
#!/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