Class: Naming::Meta
- Inherits:
-
Object
- Object
- Naming::Meta
- Defined in:
- lib/naming.rb
Overview
Meta is a container of name and value. This is super class of all naming classes.
Class Method Summary collapse
-
.name ⇒ Symbol
Return the name as symbol.
-
.name=(name) ⇒ void
private
Set the name.
-
.others(array) ⇒ Object
Collect objects from the array excluding named objects which have the same name.
-
.values(array) ⇒ Object
Extract values which have the same name from the array.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?) private
- #hash ⇒ Object private
-
#initialize(value) ⇒ Meta
constructor
A new instance of Meta.
-
#name ⇒ Symbol
Return the name.
-
#value ⇒ Object
Return the value.
Constructor Details
#initialize(value) ⇒ Meta
Returns a new instance of Meta.
114 115 116 |
# File 'lib/naming.rb', line 114 def initialize(value) @value = value end |
Class Method Details
.name ⇒ Symbol
Return the name as symbol. It is just name, doesn’t include module path.
96 97 98 |
# File 'lib/naming.rb', line 96 def name self.to_s.split("::").last.to_sym end |
.name=(name) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Set the name.
107 108 109 |
# File 'lib/naming.rb', line 107 def name=(name) @name = name unless @name end |
.others(array) ⇒ Object
Collect objects from the array excluding named objects which have the same name.
85 86 87 |
# File 'lib/naming.rb', line 85 def others(array) array.select{|elt| not(elt.kind_of?(self))} end |
.values(array) ⇒ Object
Extract values which have the same name from the array.
66 67 68 |
# File 'lib/naming.rb', line 66 def values(array) array.select{|elt| elt.kind_of?(self)}.map{|elt| elt.value} end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
135 136 137 138 |
# File 'lib/naming.rb', line 135 def ==(other) return false unless other.kind_of?(self.class) @value == other.value end |
#hash ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
142 143 144 |
# File 'lib/naming.rb', line 142 def hash @value.hash end |
#name ⇒ Symbol
Return the name.
122 123 124 |
# File 'lib/naming.rb', line 122 def name self.class.name end |
#value ⇒ Object
Return the value.
130 131 132 |
# File 'lib/naming.rb', line 130 def value @value end |