Class: ConvenientService::Utils::Module::FetchOwnConst Private
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::Module::FetchOwnConst
- Defined in:
- lib/convenient_service/utils/module/fetch_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 a constant that is defined directly in module or defines it there.
Instance Attribute Summary collapse
- #const_name ⇒ Object readonly private
- #fallback_block ⇒ Object readonly private
- #mod ⇒ Object readonly private
Instance Method Summary collapse
-
#call ⇒ Object
private
Value of own const.
- #initialize(mod, const_name, &fallback_block) ⇒ void constructor private
Methods inherited from Support::Command
Constructor Details
#initialize(mod, const_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.
72 73 74 75 76 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 72 def initialize(mod, const_name, &fallback_block) @mod = mod @const_name = const_name @fallback_block = fallback_block end |
Instance Attribute Details
#const_name ⇒ Object (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.
58 59 60 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 58 def const_name @const_name end |
#fallback_block ⇒ Object (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.
64 65 66 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 64 def fallback_block @fallback_block end |
#mod ⇒ Object (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.
52 53 54 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 52 def mod @mod end |
Instance Method Details
#call ⇒ Object
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.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 84 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 mod.const_get(const_name, false) if mod.const_defined?(const_name, false) return mod.const_set(const_name, fallback_block.call) if fallback_block nil end |