Class: ConvenientService::Utils::Object::InstanceVariableFetch
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::Object::InstanceVariableFetch
- Defined in:
- lib/convenient_service/utils/object/instance_variable_fetch.rb
Overview
Can be used instead of return @ivar if defined? @ivar
.
Instance Attribute Summary collapse
-
#fallback_block ⇒ Object
readonly
Returns the value of attribute fallback_block.
-
#ivar_name ⇒ Object
readonly
Returns the value of attribute ivar_name.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#call ⇒ Object
Value of ivar.
- #initialize(object, ivar_name, &fallback_block) ⇒ void constructor
Methods inherited from Support::Command
Constructor Details
#initialize(object, ivar_name, &fallback_block) ⇒ void
43 44 45 46 47 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 43 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)
Returns the value of attribute fallback_block.
35 36 37 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 35 def fallback_block @fallback_block end |
#ivar_name ⇒ Object (readonly)
Returns the value of attribute ivar_name.
29 30 31 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 29 def ivar_name @ivar_name end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
23 24 25 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 23 def object @object end |
Instance Method Details
#call ⇒ Object
Returns Value of ivar. Can be any type.
52 53 54 55 56 57 58 |
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 52 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 |