Ruby Notes - Classes

language-features ruby

What do they look like?

class BookInStock
	def Initialize(isbn, price)
		@isbn = isbn
		@price = Float(price)
	end

	def to_s
		"ISBN: #{@isbn}, price: #{@price}"
	end
end

What is the @ symbol?

It represents the instance variables.

What is to_s?

It is the toString method in ruby.

What is the difference between the puts method and the p method?

The puts method prints the output of to_s method and the p method puts the output of the object.

How do you initialize a class

Using the new keyword. person = Person.new