In the following code, p
and puts
give the same output.
class Book
def initialize(title, price)
@title = title
@price = price
end
def to_s
"book with title=#{@title} and price=#{@price}"
end
end
book1 = Book.new("Book of Ruby", 50.63)
puts book1 # => book with title=Book of Ruby and price=50.63
p book1 # => book with title=Book of Ruby and price=50.63
Why is this the case? p
should have called book1.inspect
instead of book1.to_s
.