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:



40
41
42
43
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 40

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.



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

def const_name
  @const_name
end

#modObject (readonly)

Returns the value of attribute mod.



27
28
29
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 27

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.



48
49
50
51
52
53
54
55
56
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 48

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