Last active
August 29, 2015 14:16
-
-
Save mattmartini/4f5be07f5a6f84a1f3d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`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" | |
AwesomePrint.irb! doesn't exist in the old version: | |
undefined method `irb!' for AwesomePrint:Module | |
Awesome Print version: 1.0.2 | |
This item, box, was used 1 times. Total Item use: 1 | |
#<Item:0x7fe13b921250 | |
@count = 1, | |
attr_accessor :quantity = 3, | |
attr_reader :name = "box", | |
attr_reader :value = 2.5 | |
> | |
=> true | |
2.1.5 :002 > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment