Class: ConvenientService::Utils::Object::InstanceVariableFetch Private
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::Object::InstanceVariableFetch
- Defined in:
- lib/convenient_service/utils/object/instance_variable_fetch.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Can be used instead of return @ivar if defined? @ivar.
Instance Attribute Summary collapse
- #fallback_block ⇒ Object readonly private
- #ivar_name ⇒ Object readonly private
- #object ⇒ Object readonly private
Instance Method Summary collapse
-
#call ⇒ Object
private
Value of ivar.
- #initialize(object, ivar_name, &fallback_block) ⇒ void constructor private
Methods inherited from Support::Command
Constructor Details
#initialize(object, ivar_name, &fallback_block) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 40 def initialize(object, ivar_name, &fallback_block) @object = object @ivar_name = ivar_name @fallback_block = fallback_block end |
Instance Attribute Details
#fallback_block ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 32 def fallback_block @fallback_block end |
#ivar_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 26 def ivar_name @ivar_name end |
#object ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 20 def object @object end |
Instance Method Details
#call ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Value of ivar. Can be any type.
49 50 51 52 53 54 55 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 49 def call return object.instance_variable_get(ivar_name) if object.instance_variable_defined?(ivar_name) return object.instance_variable_set(ivar_name, fallback_block.call) if fallback_block nil end |