Method: Hyperloop::Context.set_var
- Defined in:
- lib/hyperloop/context.rb
.set_var(ctx, var, force: nil) ⇒ Object
Replace @foo ||= … with Context.set_var(self, :@foo) { … } If reset! has been called then the instance variable will be record, and will be reset on the next call to reset! If you want to record the current value of the instance variable then set force to true.
14 15 16 17 18 19 20 |
# File 'lib/hyperloop/context.rb', line 14 def self.set_var(ctx, var, force: nil) inst_value_b4 = ctx.instance_variable_get(var) if @context && !@context[ctx].key?(var) && (force || !inst_value_b4) @context[ctx][var] = (inst_value_b4 && inst_value_b4.dup) end inst_value_b4 || ctx.instance_variable_set(var, yield) end |