Module: Kernel

Defined in:
lib/ubsafe/extensions/ubsafe_kernel_extensions.rb

Instance Method Summary collapse

Instance Method Details

#alias_class_method(orig_name, new_name = "_ubsafe_original_#{orig_name}") ⇒ Object

Aliases a class method to a new name. It will only do the aliasing once, to prevent issues with reloading a class and causing a StackLevel too deep error. The method takes two arguments, the first is the original name of the method, the second, optional, parameter is the new name of the method. If you don’t specify a new method name it will be generated with original<original_name>.

Example:

class President
  alias_class_method :good
  alias_class_method :bad, :old_bad
  def self.good
    'Bill ' + _original_good
  end
  def self.bad
    "Either #{old_bad}"
  end
end

Parameters:

  • orig_name (String)

    The original class method to alias

  • new_name (String) (defaults to: "_ubsafe_original_#{orig_name}")

    The new alias. Defaults to ‘ubsafe_original[name]’



27
28
29
30
31
32
33
# File 'lib/ubsafe/extensions/ubsafe_kernel_extensions.rb', line 27

def alias_class_method(orig_name, new_name = "_ubsafe_original_#{orig_name}")
  eval(%{
    class << self
      alias_method :#{new_name}, :#{orig_name} unless method_defined?("#{new_name}")
    end
  })
end