Stringification to_s
- to_s
class Point
property x : Float64
property y : Float64
def initialize(@x, @y)
end
def to_s
return "(#{@x}, #{@y})"
end
end
p = Point.new(2.1, 3.4)
puts p
puts p.to_s
#<Point:0x7f037505efc0>
(2.1, 3.4)
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
class Point
property x : Float64
property y : Float64
def initialize(@x, @y)
end
def to_s
return "(#{@x}, #{@y})"
end
end
p = Point.new(2.1, 3.4)
puts p
puts p.to_s
#<Point:0x7f037505efc0>
(2.1, 3.4)