Skip to content

Instantly share code, notes, and snippets.

@jlucasps
Last active August 29, 2015 14:01
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 jlucasps/49ab83b94594a8cea1db to your computer and use it in GitHub Desktop.
Save jlucasps/49ab83b94594a8cea1db to your computer and use it in GitHub Desktop.
class Caller
def self.exec_before( method_name)
@@before = method_name
end
def self.exec_after( method_name )
@@after = method_name
end
def execute( &code )
method(@@before).call
code.call
method(@@after).call
end
end
class Exec < Caller
exec_before( :say_hello )
exec_after( :say_bye )
def say_hello
puts "Hello, I'm here!"
end
def say_bye
puts "Good bye!"
end
end
exec = Exec.new
exec.execute do
puts "I do my job"
end
>> Hello, I'm here!
>> I do my job
>> Good bye!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment