Class: ThomasUtils::KeyComparer

Inherits:
Object
  • Object
show all
Defined in:
lib/thomas_utils/key_comparer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, comparer) ⇒ KeyComparer

Returns a new instance of KeyComparer.



6
7
8
9
# File 'lib/thomas_utils/key_comparer.rb', line 6

def initialize(key, comparer)
  @key = key
  @comparer = comparer
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/thomas_utils/key_comparer.rb', line 4

def key
  @key
end

Instance Method Details

#==(rhs) ⇒ Object



28
29
30
# File 'lib/thomas_utils/key_comparer.rb', line 28

def ==(rhs)
  to_s == rhs.to_s
end

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/thomas_utils/key_comparer.rb', line 32

def eql?(rhs)
  self == rhs
end

#hashObject



36
37
38
# File 'lib/thomas_utils/key_comparer.rb', line 36

def hash
  to_s.hash
end

#new_key(updated_key) ⇒ Object



11
12
13
# File 'lib/thomas_utils/key_comparer.rb', line 11

def new_key(updated_key)
  KeyComparer.new(updated_key, @comparer)
end

#quote(quote) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/thomas_utils/key_comparer.rb', line 15

def quote(quote)
  quoted_key = if key.respond_to?(:quote)
                 key.quote(quote)
               else
                 "#{quote}#{key}#{quote}"
               end
  "#{quoted_key} #{@comparer}"
end

#to_sObject



24
25
26
# File 'lib/thomas_utils/key_comparer.rb', line 24

def to_s
  "#{pretty_key} #{@comparer}"
end