Class: Riot::Gear::OnceRunnable
- Inherits:
-
RunnableBlock
- Object
- RunnableBlock
- Riot::Gear::OnceRunnable
- Defined in:
- lib/riot/gear/context/once.rb
Instance Method Summary collapse
-
#initialize(description, &definition) ⇒ OnceRunnable
constructor
A new instance of OnceRunnable.
-
#run(situation) ⇒ Array<Symbol>
Applies the provided &definition to the
situation
.
Constructor Details
#initialize(description, &definition) ⇒ OnceRunnable
Returns a new instance of OnceRunnable.
2 3 4 5 |
# File 'lib/riot/gear/context/once.rb', line 2 def initialize(description, &definition) super("[once] #{description}", &definition) @ran = false end |
Instance Method Details
#run(situation) ⇒ Array<Symbol>
Applies the provided &definition to the situation
. But, it only does so once.
12 13 14 15 16 17 18 19 20 |
# File 'lib/riot/gear/context/once.rb', line 12 def run(situation) if @ran [:once_ignored] else @ran = true situation.evaluate(&definition) [:once] end end |