Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMICHAEL P
5,191 PointsGot store.rb: 100: syntax error , unexpected keyword_end , expecting end of input . Not sure how to fix this Ruby error.
I got the following Ruby error:" Got store.rb: 100: syntax error , unexpected keyword_end , expecting end of input ."
module Inventoryable
def self.included(klass)
klass.extend(ClassMethods)
klass.extend(Enumerable)
end
module ClassMethods
def create(attributes)
object = new(attributes)
instances.push(object)
return object
end
def instances
@instances ||= []
end
def each(&block)
instances.each(&block)
end
def report(title, items)
puts "-" * 50
puts title
puts "-" * 50
items.each do |item|
line = []
line.push("Item: #{item.attributes[:name]}")
line.push("Stock: #{item.stock_count}")
if item.attributes.include?(:size)
line.push("Size: #{item.attributes[:size]}")
end
puts line.join("\t")
end
puts "-" * 50
puts "\n"
end
def in_stock_report
title = "#{self.to_s} In Stock Report"
reportable = instances.select{ |instance| instance.in_stock? }
report(title, reportable)
end
def out_of_stock_report
title = "#{self.to_s} Out Of Stock Report"
reportable = instances.select{ |instance| !instance.in_stock? }
report(title, reportable)
end
end
def stock_count
@stock_count ||= 0
end
def stock_count=(number)
@stock_count = number
end
def in_stock?
stock_count > 0
end
end
module Treehouse
class Shirt
include Inventoryable
attr_accessor :attributes
def initialize(attributes)
@attributes = attributes
end
end
class Pant
include Inventoryable
attr_accessor :attributes
def initialize(attributes)
@attributes = attributes
end
end
class Accessory
include Inventoryable
attr_accessor :attributes
def initialize(attributes)
@attributes = attributes
end
end
end
def initialize(attributes)
@attributes = attributes
end
end
shirt = Treehouse::Shirt.create(name: "MTF", size: "L")
shirt.stock_count = 10
shirt = Treehouse::Shirt.create(name: "MTF2", size: "L")
shirt = Treehouse::Shirt.create(name: "MTF", size: "M")
shirt.stock_count = 9
pant = Treehouse::Pant.create(name: "Jeans", size: "M")
pant.stock_count = 2
pant = Treehouse::Pant.create(name: "Jeans", size: "S")
pant.stock_count = 4
accessory = Treehouse::Accessory.create(name: "Belt", size: "M")
accessory.stock_count = 1
accessory = Treehouse::Accessory.create(name: "Belt", size: "L")
accessory.stock_count = 1
accessory = Treehouse::Accessory.create(name: "Necklace")
accessory.stock_count = 1
Treehouse::Shirt.in_stock_report
Treehouse::Pant.in_stock_report
Treehouse::Accessory.in_stock_report
Treehouse::Shirt.out_of_stock_report
Yann Hulot
1,874 PointsYann Hulot
1,874 Points