Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
In this video, we learn a little trick with extending and including something at the same time.
Code Samples
module Inventoryable
def self.included(klass)
klass.extend(ClassMethods)
end
module ClassMethods
def create(attributes)
object = new(attributes)
instances.push(object)
return object
end
def instances
@instances ||= []
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
class Shirt
include Inventoryable
attr_accessor :attributes
def initialize(attributes)
@attributes = attributes
end
end
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Joseph Park
Front End Web Development Techdegree Student 6,746 Points1 Answer
-
Mateusz Leśniak
4,762 Points0 Answers
-
simon lavery
17,485 Points3 Answers
-
brendan1701
11,913 Points5 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up