Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/dmorrill10-utils/class.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.alias_method_in_singleton_context(alias_method, method_to_alias) ⇒ Object



26
27
28
# File 'lib/dmorrill10-utils/class.rb', line 26

def alias_method_in_singleton_context(alias_method, method_to_alias)
  alias_method alias_method, method_to_alias
end

Instance Method Details

#alias_class_method(alias_method, method_to_alias) ⇒ Object

Parameters:

  • alias_method (#to_sym)

    A class method to alias the class method, method_to_alias.

  • method_to_alias (#to_sym)

    A class method to be aliased by alias_method.



20
21
22
# File 'lib/dmorrill10-utils/class.rb', line 20

def alias_class_method(alias_method, method_to_alias)
  singleton_class.alias_method_in_singleton_context alias_method.to_sym, method_to_alias.to_sym
end

#alias_new(alias_of_new) ⇒ Object



14
15
16
# File 'lib/dmorrill10-utils/class.rb', line 14

def alias_new(alias_of_new)
  alias_class_method alias_of_new, :new
end

#exceptions(*names) ⇒ Object

Parameters:

  • names (Array)

    A list of exception names that the calling class would like to define.



7
8
9
10
11
12
# File 'lib/dmorrill10-utils/class.rb', line 7

def exceptions(*names)
  names.each do |name|
    error_name = name.to_class_name
    const_set(error_name, Class.new(RuntimeError))
  end
end