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
51 52 53 54 55 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 51 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.
37 38 39 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 37 def ivar_name @ivar_name end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
31 32 33 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 31 def object @object end |
#value_block ⇒ Object (readonly)
Returns the value of attribute value_block.
43 44 45 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 43 def value_block @value_block end |
Instance Method Details
#call ⇒ Object
Returns Value of ivar. Can be any type.
60 61 62 |
# File 'lib/convenient_service/utils/object/memoize_including_falsy_values.rb', line 60 def call Utils::Object.instance_variable_fetch(object, ivar_name, &value_block) end |