Module: CanHaveSpecialMethods::ClassMethods

Defined in:
lib/mixins/can_have_special_methods.rb

Constant Summary collapse

@@special_methods =
{}

Instance Method Summary collapse

Instance Method Details

#special_method(sym) ⇒ Object

Public: Adds the given symbol to the list of special methods.

sym - Symbol to add.

Returns nothing.



25
26
27
28
# File 'lib/mixins/can_have_special_methods.rb', line 25

def special_method(sym)
  @@special_methods[self] ||= []
  @@special_methods[self] << sym
end

#special_methodsObject

Public: Gets the list of special methods.

Returns an Array of Symbol special method names.



33
34
35
36
37
# File 'lib/mixins/can_have_special_methods.rb', line 33

def special_methods
  for_class = @@special_methods.fetch(self, [])
  for_super = self.superclass.respond_to?(:special_methods) ? self.superclass.special_methods : []
  (for_super + for_class).uniq
end