Class: Attribute
- Inherits:
-
Object
- Object
- Attribute
- Defined in:
- lib/values/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(object) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name_or_hash, type = nil) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(name_or_hash, type = nil) ⇒ Attribute
Returns a new instance of Attribute.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/values/attribute.rb', line 5 def initialize name_or_hash,type = nil name = nil if name_or_hash.is_a? Hash name = name_or_hash[:name] type = name_or_hash[:type] else name = name_or_hash end unless(type.is_a?(Class) || type.is_a?(Heading)) type = type.class end throw "Type cant be nil, :#{name} => #{type}" if type == NilClass @name = name.to_s @type = type end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/values/attribute.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/values/attribute.rb', line 3 def type @type end |
Instance Method Details
#==(object) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/values/attribute.rb', line 33 def == object if object.equal?(self) true elsif !self.class.equal?(object.class) false else object.name == self.name && object.type == self.type end end |
#eql?(other) ⇒ Boolean
25 26 27 |
# File 'lib/values/attribute.rb', line 25 def eql? other self == other end |
#hash ⇒ Object
29 30 31 |
# File 'lib/values/attribute.rb', line 29 def hash name.hash + type.hash end |