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 Extend an Include

MICHAEL P
MICHAEL P
5,191 Points

Not Sure How To Do Ruby Challenge. Please Help!

I am not sure how to do the Ruby Challenge. Please help

The Ruby Challenge is to do the following: Create a module called ClassMethods inside of the Inventory module.

module Inventory end

class Shirt include Inventory attr_accessor :attributes

def initialize(attributes) @attributes = attributes end end

store.rb
module Inventory
end

class Shirt
  include Inventory
  attr_accessor :attributes

  def initialize(attributes)
    @attributes = attributes
  end
end

2 Answers

Hi Michael!

So, it's important to understand that the question is asking you to create a module inside the Inventory module. Modules in Ruby need to begin with the module keyword followed by the name of the module, and then close with the end keyword. As an example, if I want to create a module within a module, it would look something like this:

module Inventory
   module MyModule
   end
end

Hopefully that helps to clarify the question! Jason goes on in the video to explain how to extend and include the module, which I'm sure will be next on the list of questions. If you need further help, don't hesitate to ask!

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