Module: Ruby::Node::Extension::Has

Included in:
Ruby::Node
Defined in:
lib/config/has_ext.rb

Instance Method Summary collapse

Instance Method Details

#has_block?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/config/has_ext.rb', line 15

def has_block?
  respond_to? :block
end

#has_const?(value) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
# File 'lib/config/has_ext.rb', line 5

def has_const?(value)
  if respond_to?(:const)
    if namespace?(value)
      name = value.split('::').last
      return self.const.identifier.token == name
    end
  end
  false
end

#has_identifier?(value) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/config/has_ext.rb', line 26

def has_identifier?(value)
  if respond_to?(:identifier)
    id = self.identifier

    if namespace?(value)
      return id.token.to_s == value.to_s if id.respond_to?(:token)
      if id.respond_to?(:identifier)
        name = value.split('::').last
        return id.identifier.token == name
      end
    end
  else
    has_const?(value)
  end
end

#has_namespace?(value) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/config/has_ext.rb', line 19

def has_namespace?(value)
  if respond_to?(:namespace)
    return self.namespace.identifier.token == value
  end
  false
end