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 trial

Ruby Ruby Modules Store Inventory Using Modules Stock Counts

def stock_count=(number)

I get the error undefined method 'stock_count=' with this code:

module Inventoryable

  def stock_count
    @stock_count ||= 0  
  end

  def stock_count=(number)
    @stock_count = number
  end

end

class Shirt
  attr_accessor :attributes

  def initialize(attributes)
    @attributes = attributes
  end
end

class Pant
  attr_accessor :attributes

  def initialize(attributes)
    @attributes = attributes
  end
end

class Accessory
  attr_accessor :attributes

  def initialize(attributes)
    @attributes = attributes
  end
end

shirt1 = Shirt.new(name: "MTF", size: "L")
shirt2 = Shirt.new(name: "MTF", size: "M")

shirt1.stock_count = 10

puts "Shirt 1 stock count: %s" % shirt1.stock_count
puts "Shirt 2 stock count: %s" % shirt2.stock_count

1 Answer

Juan Pablo Pinto Santana
Juan Pablo Pinto Santana
15,719 Points

Hi there!

You need to include the Inventoryable module inside the Shirt Class like this:

class Shirt
    include Inventoryable

...
end

Happy coding!