Created
April 10, 2009 06:16
-
-
Save bjeanes/92968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point | |
attr_reader :x, :y | |
def initialize(x, y) | |
@x, @y = x, y | |
end | |
def ~ point | |
Math.sqrt((point.x - self.x) ** 2 + | |
(point.y - self.y) ** 2) | |
end | |
end | |
p1,p2 = Point.new(-4,14), Point.new(12,-34) | |
puts (p1.~(p2)) | |
# puts (p1 ~ p2) # ArgumentError: wrong number of arguments (0 for 1) | |
# Treating p1 ~ p2 as p1(~p2) instead of p1.~(p2) | |
# Seems inconsistent with behaviour of +@ an -@ | |
class Huh | |
def ~@ | |
puts "a" | |
end | |
def ~ | |
puts "b" | |
end | |
end | |
~Huh.new # => "b" | |
# Why? shouldn't this call Huh#~@ and leave Huh#~ for something link h1 ~ h2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment