Class: ConvenientService::Utils::Module::FetchOwnConst
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::Module::FetchOwnConst
- Defined in:
- lib/convenient_service/utils/module/fetch_own_const.rb
Instance Attribute Summary collapse
-
#const_name ⇒ Object
readonly
Returns the value of attribute const_name.
-
#fallback_block ⇒ Object
readonly
Returns the value of attribute fallback_block.
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
Instance Method Summary collapse
-
#call ⇒ Object
Value of own const.
- #initialize(mod, const_name, &fallback_block) ⇒ void constructor
Methods inherited from Support::Command
Constructor Details
#initialize(mod, const_name, &fallback_block) ⇒ void
62 63 64 65 66 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 62 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)
Returns the value of attribute const_name.
48 49 50 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 48 def const_name @const_name end |
#fallback_block ⇒ Object (readonly)
Returns the value of attribute fallback_block.
54 55 56 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 54 def fallback_block @fallback_block end |
#mod ⇒ Object (readonly)
Returns the value of attribute mod.
42 43 44 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 42 def mod @mod end |
Instance Method Details
#call ⇒ Object
Returns Value of own const. Can be any type.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/convenient_service/utils/module/fetch_own_const.rb', line 74 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 |