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

Kevin Naegele
Kevin Naegele
10,868 Points

Stock count module is not working

I am doing the stock count module and getting an error. I have retyped the entire vidoe, and have tried just adding to the file supplyed for the video and it is still not working.

This is the error outlit.rb:23:in <class:Pants>': undefined methodatrr_accessor' for Pants:Class (NoMethodError) from outlit.rb:22:in `<main>'

Here is my code.

module Inventoryable

  def stock_count
    @stock_count ||= 0
  end

  def stock_count=(number)
    @stock_count = number
  end
end


class Shirt
  include Inventoryable
  attr_accessor :attributes

  def initailize(attributes)
    @attributes = attributes
  end
end

class Pants 
  atrr_accessor :attributes

 def initailize(attributes)
    @attributes = attributes
  end
end

class Accessory 
  atrr_accessor :attributes 

 def initailize(attributes)
    @attributes = attributes
  end
end

shirt1 = Shirt.new(name: "TGK", size: "L")
shirt2 = Shirt.new(name: "Harley", size: "XL")

shirt1.stock_count = 10


puts " Shirt 1 stock count : %s" % shirt1.stock_count 
puts " Shirt 2 stock count : %s" % shirt2.stock_count 
Sean T. Unwin
Sean T. Unwin
28,690 Points

Hi Kevin Naegele,

If you put the language name after the 3 tics when posting code it will be syntax highlighted. I have fixed it here and thought I would let you know in case you were unaware. :)

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

The first line in your Pants class, as well as the Accessory class, has a typo -- you have 2 "r"'s and 1 "t"; should be reversed:

atrr_accessor :attributes

# should be:

attr_accessor :attributes

I believe you will also want to add the include Inventoryable statement for each of the those classes. It should be placed directly above the attr_accessor :attributes line, which would make those statements the first and second lines, respectively, in each class.

Hie guys if you are stuck on the challenge, you can try this code below, it has made me to pass the challenge. Just try it. Wish you the best of luck.

module Inventory def stock_count @stock_count ||= 0 end end

module Treehouse class Shirt include Inventory attr_accessor :attributes

def initialize(attributes)
  @attributes = attributes
end

end

class Pant include Inventory attr_accessor :attributes

def initialize(attributes)
  @attributes = attributes
end

end end

shirt1 = Treehouse::Shirt.new(name: "MMD", size: "L") shirt2 = Treehouse::Shirt.new(name: "Masango", size: "XL")

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