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

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/module/get_own_const.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.

Returns constant defined directly in mod.

Examples:

Common usage.

module Test
end

ConvenientService::Utils::Module::GetOwnConst.call(Test, :File)
# => nil, not File from Ruby Core.

module Test
  class File
  end
end

ConvenientService::Utils::Module::GetOwnConst.call(Test, :File)
# => Test::File

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(mod, const_name) ⇒ 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:

Since:

  • 1.0.0



50
51
52
53
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 50

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

Instance Attribute Details

#const_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



43
44
45
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 43

def const_name
  @const_name
end

#modObject (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



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

def mod
  @mod
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 own const. Can be any type.

Returns:

  • (Object)

    Value of own const. Can be any type.

Since:

  • 1.0.0



58
59
60
61
62
63
64
65
66
# File 'lib/convenient_service/utils/module/get_own_const.rb', line 58

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