Class: ConvenientService::Utils::Object::MemoizeIncludingFalsyValues

Inherits:
Support::Command
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(object, ivar_name, &value_block) ⇒ void

Parameters:

  • object (Object)
  • ivar_name (Symbol)
  • value_block (Proc)


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_nameObject (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

#objectObject (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_blockObject (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

#callObject

Returns Value of ivar. Can be any type.

Returns:

  • (Object)

    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