Next 1.0 Classes Prev

Classes

Ruby comes with the large pre-defined class hierarchy.

Creating a new class

class Person
	attr :name
	attr :email

	def initialize(name, email='no@email.org')
		@name = name
		@email = email
	end
end

monger = Person.new("Mr. Hacker", "mr@hacker.org")
p monger.name
"Mr. Hacker"

Next Ruby for Perl programmers Prev