-
Notifications
You must be signed in to change notification settings - Fork 7
Inheritance
Alexander Popov edited this page Feb 19, 2017
·
1 revision
class FlameController
def execute(method)
puts 'FlameController before'
public_send method
puts 'FlameController after'
rescue => exception
puts 'FlameController rescue'
raise exception
end
end
class BaseController < FlameController
def execute(method)
puts 'BaseController before'
super
puts 'BaseController after'
rescue => exception
puts 'BaseController rescue'
raise exception
end
end
class MyController < BaseController
def regular
puts 'MyController regular'
end
def error
puts 'MyController error'
raise
end
def execute(method)
puts 'MyController before'
super
puts 'MyController after'
rescue => exception
puts 'MyController rescue'
raise exception
end
end
controller = MyController.new
controller.execute(:regular)
# -----> MyController before
# ---> BaseController before
# -> FlameController before
# -----> MyController regular
# -> FlameController after
# ---> BaseController after
# -----> MyController after
controller.execute(:error)
# -----> MyController before
# ---> BaseController before
# -> FlameController before
# -----> MyController error
# -> FlameController rescue
# ---> BaseController rescue
# -----> MyController rescue