Class: Resilient::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/resilient/key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Key

Returns a new instance of Key.

Raises:

  • (TypeError)


17
18
19
20
# File 'lib/resilient/key.rb', line 17

def initialize(name)
  raise TypeError, "name must be a String" unless name.is_a?(String)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/resilient/key.rb', line 15

def name
  @name
end

Class Method Details

.wrap(string_or_instance) ⇒ Object

Internal: Takes a string name or instance of a Key and always returns a Key instance.



6
7
8
9
10
11
12
13
# File 'lib/resilient/key.rb', line 6

def self.wrap(string_or_instance)
  case string_or_instance
  when self, NilClass
    string_or_instance
  else
    new(string_or_instance)
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



22
23
24
# File 'lib/resilient/key.rb', line 22

def ==(other)
  self.class == other.class && name == other.name
end

#hashObject



27
28
29
# File 'lib/resilient/key.rb', line 27

def hash
  @name.hash
end