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 17 18 |
# File 'lib/julewire/core/integration/ivar_state.rb', line 12 def fetch(owner) return unless owner.respond_to?(:instance_variable_get) owner.instance_variable_get(@marker) rescue StandardError nil end |
#fetch_or_store(owner) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/julewire/core/integration/ivar_state.rb', line 29 def fetch_or_store(owner) existing = fetch(owner) return existing if existing store(owner, yield) end |
#store(owner, value) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/julewire/core/integration/ivar_state.rb', line 20 def store(owner, value) return value unless owner.respond_to?(:instance_variable_set) owner.instance_variable_set(@marker, value) value rescue StandardError value end |