Skip to content

Instantly share code, notes, and snippets.

@matthewrudy
Created June 25, 2019 15:55
Show Gist options
  • Save matthewrudy/431198f42da890e33672700bee2eaaef to your computer and use it in GitHub Desktop.
Save matthewrudy/431198f42da890e33672700bee2eaaef to your computer and use it in GitHub Desktop.
Example of using Protected methods for comparisons
class CompetitiveEater
include Comparable
def <=>(other)
spicy_tolerance <=> other.spicy_tolerance
end
def initialize(spicy_tolerance)
@spicy_tolerance = spicy_tolerance
end
protected
# a secret, other non-eaters won't understand
# but we know this is the most important metric
attr_reader :spicy_tolerance
end
one = CompetitiveEater.new(1)
million = CompetitiveEater.new(1_000_000)
puts "is one better than one million?: #{one > million}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment