class Animal
def initialize(options = {})
@type = options[:type]
@name = options[:name]
@legs = options[:legs]
@noise = options[:noise]
end
def type?
return @type
end
def name?
return @name
end
def noise?
return @noise
end
def legs?
return @legs
end
end
dog = Animal.new(:type => "Dog", :name => "Pipin", :legs => 4, :noise => "Woof")
puts "#{dog.name?} the #{dog.type?} has #{dog.legs?} legs and goes \"#{dog.noise?}!\"\n"
cow = Animal.new(:type => "Cow", :name => "Kevin", :legs => 4, :noise => "Moo")
puts "#{cow.name?} the #{cow.type?} has #{cow.legs?} legs and goes \"#{cow.noise?}!\"\n"
Output:
Pipin the Dog has 4 legs and goes "Woof!"
Kevin the Cow has 4 legs and goes "Moo!"
…a simple class which turns the dog and cow variables into objects, like small boxes with information referring to that animal. By the way — I hope code isn't classed as words, else I've failed to describe it in under 64! :P