#create class
class Produce
attr_accessor :name, :type, :color
def initialize name, type, color
@name = name
@type = type
@color = color
end
def get_info
return "#{@name} #{@type} #{@color}"
end
end
#ruby mapping objects
new_map = [['banana','fruit','yellow'],['peas','vegetable','olive green'],['eggs','dairy', 'white']].map { |x,y,z| Produce.new x, y, z }
new_map.each { |obj| puts obj.get_info()}
No comments:
Post a Comment