Module: Aliasable::ControllingClassMethods
- Defined in:
- lib/classy/aliasable.rb
Overview
Methods for the class or module that directly includes Aliasable.
Instance Method Summary collapse
-
#find(nick) ⇒ Object
When passed a class, just returns it.
-
#forget_aliases ⇒ Object
Forget all known aliases.
-
#included(klass) ⇒ Object
Handle a class including a module that has included Aliasable.
Instance Method Details
#find(nick) ⇒ Object
When passed a class, just returns it. When passed a symbol that is an alias for a class, returns that class.
ParentClass.find(AliasedSubclass) # => AliasedSubclass
ParentClass.find(:kid) # => AliasedSubclass
94 95 96 97 |
# File 'lib/classy/aliasable.rb', line 94 def find( nick ) return nick if nick.kind_of? Class aliases[nick] end |
#forget_aliases ⇒ Object
Forget all known aliases. Mainly useful for testing purposes.
101 102 103 |
# File 'lib/classy/aliasable.rb', line 101 def forget_aliases aliases.clear end |
#included(klass) ⇒ Object
Handle a class including a module that has included Aliasable. Since the contolling module has extended this module, this method ends up being called when the controlling module is included.
As a minor side effect, an instance method named #included ends up on any class that directly includes Aliasable. If you know an elegant way to avoid this, I welcome pull requests. :-)
:nodoc:
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/classy/aliasable.rb', line 73 def included( klass ) klass.extend AliasingClassMethods klass.extend UniversalClassMethods # Hoo boy. We need to set the @@classy_aliases class variable in the # including class to point to the same actual hash object that the # @@classy_aliases variable on the controlling module points to. When # everything is class based, this is done automatically, since # sub-classes share class variables. # klass.send(:class_variable_set, :@@classy_aliases, self.send(:class_variable_get, :@@classy_aliases)) super end |