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.
46 47 48 |
# File 'lib/plumb/composable.rb', line 46 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.
51 52 53 54 55 56 57 58 |
# File 'lib/plumb/composable.rb', line 51 def self.included(base) 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
73 74 75 76 77 78 |
# File 'lib/plumb/composable.rb', line 73 def freeze return self if frozen? @name = Name.new(_inspect) super end |
#inspect ⇒ Object
82 |
# File 'lib/plumb/composable.rb', line 82 def inspect = name.to_s |
#node_name ⇒ Object
84 |
# File 'lib/plumb/composable.rb', line 84 def node_name = self.class.name.split('::').last.to_sym |