Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created September 1, 2011 01:00
Show Gist options
  • Select an option

  • Save steveklabnik/1185156 to your computer and use it in GitHub Desktop.

Select an option

Save steveklabnik/1185156 to your computer and use it in GitHub Desktop.
ghost methods!
class Student
def method_missing(name, *args, &blk)
"Sorry, I don't understand '#{name}'!"
end
end
s = Student.new
s.no_idea #=> "Sorry, I don't understand 'no_idea'!"
t = Student.new
t.no_idea #=> "Sorry, I don't understand 'no_idea'!"
def t.method_missing(name, *args, &blk)
if name.to_s.start_with? "no"
"intercepting '#{name}'!"
else
super
end
end
s.no_idea #=> "Sorry, I don't understand 'no_idea'!"
t.no_idea #=> "intercepting 'no_idea'!"
t.some_idea #=> "Sorry, I don't understand 'some_idea'!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment