Class: Gamefic::Binding
- Inherits:
-
Object
- Object
- Gamefic::Binding
- Defined in:
- lib/gamefic/binding.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#narrative ⇒ Object
readonly
Returns the value of attribute narrative.
Class Method Summary collapse
Instance Method Summary collapse
- #call(*args) ⇒ Object (also: #[])
-
#initialize(narrative, code) ⇒ Binding
constructor
A new instance of Binding.
Constructor Details
#initialize(narrative, code) ⇒ Binding
31 32 33 34 |
# File 'lib/gamefic/binding.rb', line 31 def initialize(narrative, code) @narrative = narrative @code = code end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
27 28 29 |
# File 'lib/gamefic/binding.rb', line 27 def code @code end |
#narrative ⇒ Object (readonly)
Returns the value of attribute narrative.
25 26 27 |
# File 'lib/gamefic/binding.rb', line 25 def narrative @narrative end |
Class Method Details
.for(object) ⇒ Object
20 21 22 |
# File 'lib/gamefic/binding.rb', line 20 def for(object) registry.fetch(object, []).last end |
.pop(object) ⇒ Object
15 16 17 18 |
# File 'lib/gamefic/binding.rb', line 15 def pop(object) registry[object].pop registry.delete(object) if registry[object].empty? end |
.push(object, narrative) ⇒ Object
10 11 12 13 |
# File 'lib/gamefic/binding.rb', line 10 def push(object, narrative) registry[object] ||= [] registry[object].push narrative end |
.registry ⇒ Object
6 7 8 |
# File 'lib/gamefic/binding.rb', line 6 def registry @registry ||= {} end |
Instance Method Details
#call(*args) ⇒ Object Also known as: []
36 37 38 39 40 41 |
# File 'lib/gamefic/binding.rb', line 36 def call(*args) args.each { |arg| Binding.push arg, @narrative } @narrative.instance_exec(*args, &@code) ensure args.each { |arg| Binding.pop arg } end |