Skip to content

Instantly share code, notes, and snippets.

@vonconrad
Forked from nusco/after_method_missing.rb
Created October 7, 2010 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vonconrad/614393 to your computer and use it in GitHub Desktop.
Save vonconrad/614393 to your computer and use it in GitHub Desktop.
class DoNotDisturb
def initialize
@desk = InformationDesk.new
end
def method_missing(name, *args)
unless name.to_s == "emergency"
hour = Time.now.hour
raise "Out for lunch" if hour >= 12 && hour < 14
end
@desk.send(name, *args)
end
end
# At 12:30...
DoNotDisturb.new.emergency # => "emergency() called"
DoNotDisturb.new.flights # ~> -:37:in `method_missing': Out for lunch (RuntimeError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment