Class: Julewire::Core::Integration::IvarState
- Inherits:
-
Object
- Object
- Julewire::Core::Integration::IvarState
- Defined in:
- lib/julewire/core/integration/ivar_state.rb
Instance Method Summary collapse
- #fetch(owner) ⇒ Object
- #fetch_or_store(owner) ⇒ Object
-
#initialize(marker) ⇒ IvarState
constructor
A new instance of IvarState.
- #store(owner, value) ⇒ Object
Constructor Details
#initialize(marker) ⇒ IvarState
Returns a new instance of IvarState.
8 9 10 |
# File 'lib/julewire/core/integration/ivar_state.rb', line 8 def initialize(marker) @marker = marker end |
Instance Method Details
#fetch(owner) ⇒ Object
12 13 14 15 16 |
# File 'lib/julewire/core/integration/ivar_state.rb', line 12 def fetch(owner) owner.instance_variable_get(@marker) rescue StandardError nil end |
#fetch_or_store(owner) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/julewire/core/integration/ivar_state.rb', line 24 def fetch_or_store(owner) existing = fetch(owner) return existing if existing store(owner, yield) end |
#store(owner, value) ⇒ Object
18 19 20 21 22 |
# File 'lib/julewire/core/integration/ivar_state.rb', line 18 def store(owner, value) owner.instance_variable_set(@marker, value) rescue StandardError value end |