Class: Use

Inherits:
Object
  • Object
show all
Defined in:
lib/Olib/core/use.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, &block) ⇒ Use

Returns a new instance of Use.



4
5
6
7
8
# File 'lib/Olib/core/use.rb', line 4

def initialize(item, &block)
  fail Exception, "Use(#{item}) did not have a container" if item.container.nil?
  @item = item
  both(&block) if block
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



2
3
4
# File 'lib/Olib/core/use.rb', line 2

def item
  @item
end

Instance Method Details

#both(&block) ⇒ Object



30
31
32
33
34
35
# File 'lib/Olib/core/use.rb', line 30

def both(&block)
  empty_hands
  @item.take
  self.run(&block)
  fill_hands
end

#left(&block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/Olib/core/use.rb', line 15

def left(&block)
  empty_left_hand
  @item.take
  Char.swap if Char.right.id == @item.id
  self.run(&block)
  fill_left_hand
end

#right(&block) ⇒ Object



23
24
25
26
27
28
# File 'lib/Olib/core/use.rb', line 23

def right(&block)
  empty_right_hand
  @item.take
  self.run(&block)
  fill_right_hand
end

#run {|@item| ... } ⇒ Object

Yields:



10
11
12
13
# File 'lib/Olib/core/use.rb', line 10

def run(&block)
  yield @item
  @item.container.add(@item) unless item.gone?
end