module Surroundings
Public Class Methods
included(base)
click to toggle source
# File lib/surroundings.rb, line 3 def self.included(base) base.instance_eval do def surrounding_macros @surrounding_macros ||= [] end def inherited(subclass) subclass.instance_variable_set(:@surrounding_macros, self.surrounding_macros.dup) super end self.extend(Module.new { def new(*) instance = super self.surrounding_macros.each { |macro| instance.extend macro } return instance end }) def before(method, *args, &block) self.surrounding_macros << Module.new do define_method method do |*args| self.instance_exec(*args, &block) super(*args) end end end def after(method, *args, &block) self.surrounding_macros << Module.new do define_method method do |*args| result = super(*args) self.instance_exec(*args, &block) result end end end end end
Public Instance Methods
after(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/surroundings.rb, line 34 def after(method, *args, &block) self.surrounding_macros << Module.new do define_method method do |*args| result = super(*args) self.instance_exec(*args, &block) result end end end
before(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/surroundings.rb, line 25 def before(method, *args, &block) self.surrounding_macros << Module.new do define_method method do |*args| self.instance_exec(*args, &block) super(*args) end end end
inherited(subclass)
click to toggle source
Calls superclass method
# File lib/surroundings.rb, line 10 def inherited(subclass) subclass.instance_variable_set(:@surrounding_macros, self.surrounding_macros.dup) super end
surrounding_macros()
click to toggle source
# File lib/surroundings.rb, line 6 def surrounding_macros @surrounding_macros ||= [] end