Print out a class : inspect « Class « Ruby






Print out a class


class Dog
  def initialize(name, age)
    @name = name
    @age = age * 7 #Compensate for dog years
  end
end

spot = Dog.new("Spot", 2.1)
spot.inspect
# => "#<Dog:0xb7c16bec @name=\"Spot\", @age=14.7>"

 








Related examples in the same category

1.Override the inspect the method to provide a better print out