Skip to content

Instantly share code, notes, and snippets.

@willmcneilly
Last active August 29, 2015 13:58
Show Gist options
  • Save willmcneilly/10008643 to your computer and use it in GitHub Desktop.
Save willmcneilly/10008643 to your computer and use it in GitHub Desktop.
# Takes an interger and outputs as a string representation
def ascending?(first, second, third)
first < second && second < third
end
def descending?(first, second, third)
first > second && second > third
end
def never_descending?(first, second, third)
first <= second && second <= third
end
class FunnyNumber
def initialize(int_rep)
@rep = "n" * int_rep
end
def inspect
"FunnyNumber (#{@rep.length}) #{@rep}"
end
def as_integer
@rep.length
end
def <(other)
self.as_integer < other.as_integer
end
def >(other)
self.as_integer > other.as_integer
end
def <=(other)
self.as_integer <= other.as_integer
end
end
new_one = FunnyNumber.new(13)
new_two = FunnyNumber.new(33)
new_three = FunnyNumber.new(53)
new_four = FunnyNumber.new(1)
p new_one < new_two
p ascending?(new_one, new_two, new_three)
p descending?(new_three, new_two, new_one)
p never_descending?(new_one, new_two, new_four)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment