Skip to content

Instantly share code, notes, and snippets.

@kurotaky
Created September 5, 2014 02:18
Show Gist options
  • Save kurotaky/08eef9284ec1c198c2be to your computer and use it in GitHub Desktop.
Save kurotaky/08eef9284ec1c198c2be to your computer and use it in GitHub Desktop.
Ruler
# パーフェクトRuby p137
class Ruler
attr_accessor :length
def initialize(length)
self.length = length
end
def ==(other)
length == other.length
end
end
ruler1 = Ruler.new(30)
ruler2 = Ruler.new(30)
p ruler1 == ruler2
ruler2.length = 40
p ruler1 == ruler2
p ruler1 == 'a' * 30
p ruler1 == 'a' * 31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment