class Human
def initialize(name, nationality)
@name=name
@nationality=nationality
end
attr_reader :nationality
def talk_english
print "My name is ", @name, "\n"
end
def talk_japanese
print "私の名前は ", @name, " です\n"
end
end
member = []
member << Human.new("Nancy", "American")
member << Human.new("Masa", "Japanese")
member << Human.new("Konno", "Japanese")
member.each do |who|
if who.nationality == "American"
who.talk_english
elsif who.nationality == "Japanese"
who.talk_japanese
end
end
|