Class: BeanSprout::Bean
- Inherits:
-
Object
- Object
- BeanSprout::Bean
- Includes:
- PackagePrivate::InternalClass
- Defined in:
- lib/bean_sprout/account.rb
Overview
TODO: abstract :id?
Instance Attribute Summary collapse
-
#balance ⇒ Object
readonly
Returns the value of attribute balance.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#sprouts ⇒ Object
readonly
Returns the value of attribute sprouts.
Attributes included from PackagePrivate::InternalClass
Instance Method Summary collapse
- #grow(sprout) ⇒ Object
-
#initialize(id, currency) ⇒ Bean
constructor
A new instance of Bean.
- #pick(sprout) ⇒ Object
Methods included from PackagePrivate::InternalClass
#bind_public_interface, included
Constructor Details
#initialize(id, currency) ⇒ Bean
12 13 14 15 16 17 18 |
# File 'lib/bean_sprout/account.rb', line 12 def initialize id, currency @id = id @currency = currency @sprouts = Set.new @balance = 0 end |
Instance Attribute Details
#balance ⇒ Object (readonly)
Returns the value of attribute balance.
8 9 10 |
# File 'lib/bean_sprout/account.rb', line 8 def balance @balance end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
8 9 10 |
# File 'lib/bean_sprout/account.rb', line 8 def currency @currency end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/bean_sprout/account.rb', line 8 def id @id end |
#sprouts ⇒ Object (readonly)
Returns the value of attribute sprouts.
8 9 10 |
# File 'lib/bean_sprout/account.rb', line 8 def sprouts @sprouts end |
Instance Method Details
#grow(sprout) ⇒ Object
20 21 22 23 |
# File 'lib/bean_sprout/account.rb', line 20 def grow sprout @sprouts.add sprout @balance += sprout.amount end |
#pick(sprout) ⇒ Object
25 26 27 28 |
# File 'lib/bean_sprout/account.rb', line 25 def pick sprout @sprouts.delete sprout @balance -= sprout.amount end |