Class: ConvenientService::Utils::Object::MemoizeIncludingFalsyValues
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::Object::MemoizeIncludingFalsyValues
- Defined in:
- lib/convenient_service/utils/object/memoize_including_falsy_values.rb
Overview
Note:
false
and nil
are the only values that are considered falsy
in Ruby.
Can be used instead of return @ivar if defined? @ivar
.
Instance Attribute Summary collapse
-
#ivar_name ⇒ Object
readonly
Returns the value of attribute ivar_name.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#value_block ⇒ Object
readonly
Returns the value of attribute value_block.
Instance Method Summary collapse
-
#call ⇒ Object
Value of ivar.
- #initialize(object, ivar_name, &value_block) ⇒ void constructor
Methods inherited from Support::Command
Constructor Details
#initialize(object, ivar_name, &value_block) ⇒ void
46 47 48 49 50 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 46 def initialize(object, ivar_name, &value_block) @object = object @ivar_name = ivar_name @value_block = value_block end |
Instance Attribute Details
#ivar_name ⇒ Object (readonly)
Returns the value of attribute ivar_name.
32 33 34 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 32 def ivar_name @ivar_name end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
26 27 28 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 26 def object @object end |
#value_block ⇒ Object (readonly)
Returns the value of attribute value_block.
38 39 40 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 38 def value_block @value_block end |
Instance Method Details
#call ⇒ Object
Returns Value of ivar. Can be any type.
55 56 57 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 55 def call Utils::Object.instance_variable_fetch(object, ivar_name, &value_block) end |