DEV Community

loading...

Discussion on: Value objects in Ruby

Collapse
edisonywh profile image
Edison Yap

You can also include the Comparable module and just implement a single spaceship operator method and all comparison classes would work.

See doc here: docs.ruby-lang.org/en/2.5.0/Compar...

Collapse
codeandclay profile image
Oliver Author • Edited

Thank you. That had slipped from my radar. Yes, Comparable gives me <, <= etc... just by defining <==>:

  def <=>(other)
    to_i <=> other.to_i
  end
Enter fullscreen mode Exit fullscreen mode
Forem Open with the Forem app