module Namebox::Old

Permits to call the previous (old) version of the method, by calling _old(…)

Public Instance Methods

_calling_old?(fullname) click to toggle source

Check if it’s already calling old, to call old and avoid recallings.

# File lib/namebox.rb, line 25
def _calling_old? fullname
  _calling_old.include? fullname
end
_old(*args, &blk) click to toggle source

Call the previous (old) version of the method.

# File lib/namebox.rb, line 30
def _old(*args, &blk)
  info = Namebox.caller_to_hash(caller[0])
  method_name = info[:method]
  method = self.method(method_name)
  owner = method.owner
  fullname = "#{owner}##{method_name}"
  set_calling_old fullname
  r = method.call(*args, &blk)
  @_calling_old.delete(fullname)
  r
end

Private Instance Methods

_calling_old() click to toggle source

stores info whether is calling the old version

# File lib/namebox.rb, line 45
def _calling_old
  @_calling_old ||= []
end
set_calling_old(fullname) click to toggle source
# File lib/namebox.rb, line 49
def set_calling_old fullname
  _calling_old.push fullname
end