public
Last active — forked from nusco/before_method_missing_1.rb

  • Download Gist
before_method_missing_1.rb
Ruby
1 2 3
class InformationDesk
include DeskTasks
end
before_method_missing_2.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class DoNotDisturb
include DeskTasks
 
def check_lunch_break
hour = Time.now.hour
raise "Out for lunch" if hour >= 12 && hour < 14
end
def emergency
"emergency() called"
end
end
 
# At 12:30...
DoNotDisturb.new.emergency # => "emergency() called"
DoNotDisturb.new.flights # ~> -:32:in `check_lunch_break': Out for lunch (RuntimeError)
desk_tasks.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
module DeskTasks
def check_lunch_break
true # or a no-op, or whatever is useful here
end
 
def emergency
# Call emergency...
check_lunch_break
"emergency() called"
end
def flights
# Provide flight information...
check_lunch_break
"flights() called"
end
def local_transports
# Return a metro map...
check_lunch_break
"local_transports() called"
end
def hotels
# Find a suitable hotel...
check_lunch_break
"hotels() called"
end
# ...even more methods
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.