Class: ConvenientService::Utils::Module::GetOwnConst

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/module/get_own_const.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(mod, const_name) ⇒ void

Parameters:



45
46
47
48
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 45

def initialize(mod, const_name)
  @mod = mod
  @const_name = const_name
end

Instance Attribute Details

#const_nameObject (readonly)

Returns the value of attribute const_name.



38
39
40
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 38

def const_name
  @const_name
end

#modObject (readonly)

Returns the value of attribute mod.



32
33
34
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 32

def mod
  @mod
end

Instance Method Details

#callObject

Returns Value of own const. Can be any type.

Returns:

  • (Object)

    Value of own const. Can be any type.



53
54
55
56
57
58
59
60
61
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 53

def call
  ##
  # NOTE: > If `inherit` is `false`, the lookup only checks the constants in the receiver:
  # https://ruby-doc.org/core-3.0.0/Module.html#method-i-const_defined-3F
  #
  return unless mod.const_defined?(const_name, false)

  mod.const_get(const_name, false)
end