Class: Sexp

Inherits:
Array show all
Defined in:
lib/wrong/d.rb,
lib/wrong/sexp_ext.rb

Instance Method Summary collapse

Instance Method Details

#assertionObject



33
34
35
36
37
38
39
40
41
# File 'lib/wrong/sexp_ext.rb', line 33

def assertion
  sexp = self
  assertion = if sexp.assertion?
                sexp
              else
                nested_assertions.first
              end
  assertion
end

#assertion?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/wrong/sexp_ext.rb', line 25

def assertion?
  self.is_a? Sexp and
    self[0] == :iter and
    self[1].is_a? Sexp and
    self[1][0] == :call and
    Wrong.config.hidden_methods.include? self[1][2]
end

#d?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
# File 'lib/wrong/d.rb', line 6

def d?
  is_a?(Sexp) &&
          (self[0] == :iter) &&
          (self[1][0] == :call) &&
          (self[1][2] == :d)
end

#each_subexp(include_root = true) {|_self| ... } ⇒ Object

visit every node in the tree, including the root, that is an Sexp todo: test todo: use deep_each instead

Yields:

  • (_self)

Yield Parameters:

  • _self (Sexp)

    the object that the method was called on



16
17
18
19
20
21
22
23
# File 'lib/wrong/sexp_ext.rb', line 16

def each_subexp(include_root = true, &block)
  yield self if include_root
  each do |child|
    if child.is_a?(Sexp)
      child.each_subexp(&block)
    end
  end
end

#to_rubyObject



7
8
9
10
11
# File 'lib/wrong/sexp_ext.rb', line 7

def to_ruby
  sexp = self.deep_clone
  ruby = Ruby2Ruby.new.process(sexp)
  ruby
end