Class: DuckPuncher::UniqueDuck

Inherits:
Duck
  • Object
show all
Defined in:
lib/duck_puncher/unique_duck.rb

Instance Attribute Summary collapse

Attributes inherited from Duck

#mod, #options, #target

Instance Method Summary collapse

Methods inherited from Duck

#call, #initialize

Constructor Details

This class inherits a constructor from DuckPuncher::Duck

Instance Attribute Details

#punch_optionsObject

Returns the value of attribute punch_options.



3
4
5
# File 'lib/duck_puncher/unique_duck.rb', line 3

def punch_options
  @punch_options
end

Instance Method Details

#<=>(other) ⇒ Object

Sorting



21
22
23
# File 'lib/duck_puncher/unique_duck.rb', line 21

def <=>(other)
  target <=> other.target
end

#eql?(other) ⇒ Boolean

Required to play nice in a Set

Returns:

  • (Boolean)


9
10
11
# File 'lib/duck_puncher/unique_duck.rb', line 9

def eql?(other)
  "#{target}-#{mod}" == "#{other.target}-#{other.mod}"
end

#hashObject



13
14
15
# File 'lib/duck_puncher/unique_duck.rb', line 13

def hash
  target.to_s.hash + mod.to_s.hash + punch_options.to_s.hash
end