
Untitled
By: a guest on
Sep 20th, 2012 | syntax:
None | size: 0.54 KB | hits: 16 | expires: Never
class Person
def speak
puts "My name is #{@name}. I am a #{@occupation}."
end
def occupation(occupation)
@occupation = occupation
end
def initialize(name)
@name = name
end
end
class House
def residents
@people.each do |person|
person.speak
end
end
def move_in(person)
@people.push(person)
end
def initialize
@people = Array.new
end
end
# examples of how the above code works:
man = Person.new("Fred")
man.occupation("Garbage man")
home = House.new
home.move_in(man)
home.residents