Module: Plumb::Naming
- Defined in:
- lib/plumb/composable.rb
Overview
This module gets included by Composable,
but only when Composable is included in classes, not extended.
The rule of this module is to assign a name to constants that point to Composable instances.
Defined Under Namespace
Classes: Name
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.included(base) ⇒ Object
When including this module, define a #node_name method on the Composable instance #node_name is used by Visitors to determine the type of node.
Instance Method Summary collapse
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
64 65 66 |
# File 'lib/plumb/composable.rb', line 64 def name @name end |
Class Method Details
.included(base) ⇒ Object
When including this module, define a #node_name method on the Composable instance #node_name is used by Visitors to determine the type of node.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/plumb/composable.rb', line 69 def self.included(base) # An anonymous class (`Class.new { include Composable }`) has no name to # derive from: leave #node_name to the instance method below, which reads # the class name at call time (by then it may have been assigned one). return unless base.name nname = base.name.split('::').last nname.gsub!(/([a-z\d])([A-Z])/, '\1_\2') nname.downcase! nname.gsub!(/_class$/, '') nname = nname.to_sym base.define_method(:node_name) { nname } end |
Instance Method Details
#freeze ⇒ Object
96 97 98 99 100 101 |
# File 'lib/plumb/composable.rb', line 96 def freeze return self if frozen? @name = Name.new(_inspect) super end |
#inspect ⇒ Object
105 |
# File 'lib/plumb/composable.rb', line 105 def inspect = name.to_s |
#node_name ⇒ Object
107 |
# File 'lib/plumb/composable.rb', line 107 def node_name = (self.class.name || 'anonymous').split('::').last.to_sym |