Class: Sexp

Inherits:
Object
  • Object
show all
Defined in:
lib/rp_extensions.rb,
lib/ruby_parser_extras.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parenObject


45
46
47
# File 'lib/rp_extensions.rb', line 45

def paren
  @paren ||= false
end

Instance Method Details

#add_all(x) ⇒ Object


61
62
63
# File 'lib/rp_extensions.rb', line 61

def add_all x
  self.concat x.sexp_body
end

#block_pass?Boolean

Returns:

  • (Boolean)

65
66
67
# File 'lib/rp_extensions.rb', line 65

def block_pass?
  any? { |s| Sexp === s && s.sexp_type == :block_pass }
end

#check_line_numbersObject


11
12
13
14
15
16
17
# File 'lib/ruby_parser_extras.rb', line 11

def check_line_numbers
  raise "bad nil line for:\n%s" % [self.pretty_inspect] if nil_line?
  raise "bad line number for:\n%s" % [self.pretty_inspect] unless
    Integer === self.line &&
    self.line >= 1 &&
    self.line <= self.line_min
end

#line_minObject

Returns the maximum line number of the children of self.


22
23
24
# File 'lib/ruby_parser_extras.rb', line 22

def line_min
  @line_min ||= [self.deep_each.map(&:line).min, self.line].compact.min
end

#nil_line?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/ruby_parser_extras.rb', line 26

def nil_line?
  self.deep_each.map(&:line).any?(&:nil?)
end

#to_symObject


54
55
56
57
# File 'lib/rp_extensions.rb', line 54

def to_sym
  raise "no: #{self.inspect}.to_sym is a bug"
  self.value.to_sym
end

#valueObject


49
50
51
52
# File 'lib/rp_extensions.rb', line 49

def value
  raise "multi item sexp" if size > 2
  last
end