Class: Campa::Symbol
- Inherits:
-
Object
- Object
- Campa::Symbol
- Defined in:
- lib/campa/symbol.rb
Overview
Represents the name to which a value is bound in a specific Context.
Implements the necessary interface to be used with success as key in Hash objects.
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
true if both #label are #==.
- #eql?(other) ⇒ Boolean
-
#hash ⇒ String
String based on label#hash.
-
#initialize(label) ⇒ Symbol
constructor
A new instance of Symbol.
Constructor Details
#initialize(label) ⇒ Symbol
Returns a new instance of Symbol.
10 11 12 |
# File 'lib/campa/symbol.rb', line 10 def initialize(label) @label = label end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'lib/campa/symbol.rb', line 7 def label @label end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if both #label are #==.
16 17 18 19 20 |
# File 'lib/campa/symbol.rb', line 16 def ==(other) return false if !other.is_a?(self.class) label == other.label end |
#eql?(other) ⇒ Boolean
Returns true if both Campa::Symbol are #== and both #hash are #==.
25 26 27 |
# File 'lib/campa/symbol.rb', line 25 def eql?(other) self == other && hash == other.hash end |
#hash ⇒ String
Returns String based on label#hash.
30 31 32 |
# File 'lib/campa/symbol.rb', line 30 def hash @hash ||= "Campa::Symbol_#{label}".hash end |