Definiendo un método to_s

Just about any class you define should have a to_s instance method to return a string representation of the object.

class Point
  def initialize(x,y)
    @x, @y = x, y
  end

  def to_s        # Return a String that represents this point
    "(#@x,#@y)"   # Just interpolate the instance variables into a string
  end
end



Casiano Rodriguez León 2015-01-07