1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
$:.unshift File.join(File.dirname(__FILE__), '../lib')
require 'equatable'
class Point
include Equatable
attr_reader :x, :y
def initialize(x, y)
@x, @y = x, y
end
end
class ColorPoint < Point
attr_reader :color
def initialize(x, y, color)
super(x, y)
@color = color
end
end
point_1 = Point.new(1, 1)
point_2 = Point.new(1, 1)
point_3 = Point.new(2, 1)
puts point_1 == point_2
puts point_1.hash == point_2.hash
puts point_1.eql?(point_2)
puts point_1.equal?(point_2)
puts point_1 == point_3
puts point_1.hash == point_3.hash
puts point_1.eql?(point_3)
puts point_1.equal?(point_3)
puts point_1.inspect
point = Point.new(1, 1)
color_point = ColorPoint.new(1, 1, :red)
puts 'Subtypes'
puts point == color_point
puts color_point == point
puts point.hash == color_point.hash
puts point.eql?(color_point)
puts point.equal?(color_point)
|