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.


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

def initialize(item, &block)
  @item = item
  both(&block) if block
end

Instance Attribute Details

#itemObject

Returns the value of attribute item


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

def item
  @item
end

Instance Method Details

#both(&block) ⇒ Object


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

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

#left(&block) ⇒ Object


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

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

#right(&block) ⇒ Object


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

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

#run(&block) ⇒ Object


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

def run(&block)
  Try.new do
    yield @item
  end
  @item.container.add(@item)
end