Module: Eco::Language::Delegation::ForDelegator::ConstDelegator::ClassMethods

Defined in:
lib/eco/language/delegation/for_delegator/const_delegator.rb

Instance Method Summary collapse

Instance Method Details

#const_defined?(str, inherit = true, delegated: true) ⇒ Boolean

rubocop:disable Style/OptionalBooleanParameter

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/eco/language/delegation/for_delegator/const_delegator.rb', line 26

def const_defined?(str, inherit = true, delegated: true) # rubocop:disable Style/OptionalBooleanParameter
  return super(str, inherit) if super(str, inherit) || !delegated
  return true                if delegated_class&.const_defined?(str, inherit)

  false
end

#const_get(str) ⇒ Object



33
34
35
36
37
38
# File 'lib/eco/language/delegation/for_delegator/const_delegator.rb', line 33

def const_get(str)
  return super                          if const_defined?(str, delegated: false)
  return delegated_class.const_get(str) if delegated_class&.const_defined?(str)

  super
end

#const_missing(str) ⇒ Object



40
41
42
43
44
# File 'lib/eco/language/delegation/for_delegator/const_delegator.rb', line 40

def const_missing(str)
  return super unless const_defined?(str)

  const_get(str)
end

#constants(inherited = true, delegated: true) ⇒ Object

rubocop:disable Style/OptionalBooleanParameter



46
47
48
49
50
51
52
53
54
# File 'lib/eco/language/delegation/for_delegator/const_delegator.rb', line 46

def constants(inherited = true, delegated: true) # rubocop:disable Style/OptionalBooleanParameter
  super(inherited).dup.tap do |consts|
    next unless delegated && delegated_class

    delegated_class.constants(inherited).each do |const|
      consts.unshift(const)
    end
  end
end