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

puts "Shirt 1 in stock?: %s" % shirt1.in_stock?

I must have missed this somewhere as there is no additional explanation on this on current video I am watching.

what does %s and % do ?

The following the whole coding

module Inventoryable 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 attr_accessor :attributes include Inventoryable

def initialize(attributes) @attributes = attributes end end

class Pants attr_accessor :attributes

def initialize(attributes) @attributes = attributes end end

class Accessories 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

I know %s is a symbol but not sure exactly what it does..

1 Answer

Ben Whitehead
Ben Whitehead
5,258 Points

%s is the print formatting code for a string, %d is for integers, and %f is for floating point numbers. Learn more about ruby print formatting here.

% by itself is also the modulo operator, also known as the remainder. for example:

5 % 2  = 1

That is 5 divided by 2 has a remainder of 1.

THANK YOU!!!!