Skip to content

Instantly share code, notes, and snippets.

@mattmartini
Created March 4, 2015 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmartini/e45c640a0415fcb505bc to your computer and use it in GitHub Desktop.
Save mattmartini/e45c640a0415fcb505bc 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
1.9.3-p547 :001 > require "~/Item.rb"
Awesome Print version: 1.1.0
This item, box, was used 1 times. Total Item use: 1
Item: box--> val:2.5 x quantity:3 ==> total: 7.5
true
1.9.3-p547 :002 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment