Class: ConvenientService::Utils::Object::InstanceVariableFetch Private

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

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

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.

Parameters:

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

Since:

  • 1.0.0



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_blockObject (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.

Since:

  • 1.0.0



32
33
34
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 32

def fallback_block
  @fallback_block
end

#ivar_nameObject (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.

Since:

  • 1.0.0



26
27
28
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 26

def ivar_name
  @ivar_name
end

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

Since:

  • 1.0.0



20
21
22
# File 'lib/convenient_service/utils/object/instance_variable_fetch.rb', line 20

def object
  @object
end

Instance Method Details

#callObject

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.

Returns:

  • (Object)

    Value of ivar. Can be any type.

Since:

  • 1.0.0



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