Class: Campa::Symbol

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(label) ⇒ Symbol

Returns a new instance of Symbol.

Parameters:

  • label (String)

    name to be bound to a value in a given Context



10
11
12
# File 'lib/campa/symbol.rb', line 10

def initialize(label)
  @label = label
end

Instance Attribute Details

#labelObject (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 #==.

Parameters:

Returns:

  • (Boolean)

    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 #==.

Parameters:

Returns:



25
26
27
# File 'lib/campa/symbol.rb', line 25

def eql?(other)
  self == other && hash == other.hash
end

#hashString

Returns String based on label#hash.

Returns:

  • (String)

    String based on label#hash.



30
31
32
# File 'lib/campa/symbol.rb', line 30

def hash
  @hash ||= "Campa::Symbol_#{label}".hash
end