Skip to content

Instantly share code, notes, and snippets.

@mattmartini
Created March 4, 2015 15:10
Show Gist options
  • Save mattmartini/5c3f61e51d2f584dc633 to your computer and use it in GitHub Desktop.
Save mattmartini/5c3f61e51d2f584dc633 to your computer and use it in GitHub Desktop.
require "awesome_print"
begin
AwesomePrint.irb!
rescue StandardError => err
warn "AwesomePrint.irb! doesn't exist in the old version:\n#{err}"
end
puts "Awesome Print version: #{AwesomePrint.version}\n\n"
class Item
attr_reader :name, :quantity, :value, :total
attr_writer :quantity
@@count = 0
def initialize(name,quantity, value)
@name = name
@quantity = quantity
@value = value
@count = 0
end
def total
@value * @quantity
end
def to_s
"Item: #{@name}--> val:#{@value} x quantity:#{@quantity} ==> total: #{self.total}"
end
def useitem
@count += 1
@@count += 1
puts "This item, #{@name}, was used #{@count} times. Total Item use: #{@@count}"
end
end
anItem = Item.new("box",3,2.5)
anItem.useitem
ap anItem
$ irb
2.1.5 :001 > require "~/Item.rb"
Awesome Print version: 1.6.1
This item, box, was used 1 times. Total Item use: 1
#<Item:0x007ff4db2fd370 @name="box", @quantity=3, @value=2.5, @count=1>
true
2.1.5 :002 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment