Class: Querly::Pattern::Kind::Conditional

Inherits:
Base
  • Object
show all
Includes:
Negatable
Defined in:
lib/querly/pattern/kind.rb

Instance Attribute Summary

Attributes included from Negatable

#negated

Attributes inherited from Base

#expr

Instance Method Summary collapse

Methods included from Negatable

#initialize

Methods inherited from Base

#initialize

Instance Method Details

#conditional?(pair) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/querly/pattern/kind.rb', line 34

def conditional?(pair)
  node = pair.node
  parent = pair.parent&.node

  case parent&.type
  when :if
    node.equal? parent.children.first
  when :while
    node.equal? parent.children.first
  when :and
    node.equal? parent.children.first
  when :or
    node.equal? parent.children.first
  when :csend
    node.equal? parent.children.first
  else
    false
  end
end

#test_kind(pair) ⇒ Object



30
31
32
# File 'lib/querly/pattern/kind.rb', line 30

def test_kind(pair)
  !negated == !!conditional?(pair)
end