Class: Lax::Tree

Inherits:
Array
  • Object
show all
Defined in:
lib/lax/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tc = {}) ⇒ Tree

Returns a new instance of Tree.



4
5
6
# File 'lib/lax/tree.rb', line 4

def initialize(tc={})
  @tc = Case.new.merge tc
end

Instance Attribute Details

#tcObject (readonly)

Returns the value of attribute tc.



3
4
5
# File 'lib/lax/tree.rb', line 3

def tc
  @tc
end

Instance Method Details

#after(aft = nil, &b) ⇒ Object



32
33
34
# File 'lib/lax/tree.rb', line 32

def after(aft=nil,&b)
  aft ? where({after: aft},&b)  : where(after: b)
end

#before(bef = nil, &b) ⇒ Object



28
29
30
# File 'lib/lax/tree.rb', line 28

def before(bef=nil,&b)
  bef ? where({before: bef},&b) : where(before: b)
end

#calling(msg, &b) ⇒ Object



12
13
14
# File 'lib/lax/tree.rb', line 12

def calling(msg,&b)
  where({msg: msg},&b)
end

#itObject



40
41
42
# File 'lib/lax/tree.rb', line 40

def it
  calling(:tap).with_block {}
end

#leavesObject



54
55
56
# File 'lib/lax/tree.rb', line 54

def leaves
  any?? map(&:leaves).flatten : [tc]
end

#on(obj, &b) ⇒ Object



8
9
10
# File 'lib/lax/tree.rb', line 8

def on(obj,&b)
  where({obj: obj},&b)
end

#raises(xptn = StandardError, &b) ⇒ Object



36
37
38
# File 'lib/lax/tree.rb', line 36

def raises(xptn=StandardError,&b)
  where({xptn: xptn},&b)
end

#returns(v, &b) ⇒ Object



44
45
46
# File 'lib/lax/tree.rb', line 44

def returns(v,&b)
  satisfies ->(e){e==v}, &b
end

#satisfies(cond = nil, &b) ⇒ Object



24
25
26
# File 'lib/lax/tree.rb', line 24

def satisfies(cond=nil,&b)
  cond ? where({cond: cond},&b) : where(cond: Lax.preproc(b))
end

#where(h, &b) ⇒ Object



48
49
50
51
52
# File 'lib/lax/tree.rb', line 48

def where(h,&b)
  t=Tree.new tc.merge h 
  Lax.preproc(b)[t] if b
  push(t).last
end

#with(*args, &b) ⇒ Object



16
17
18
# File 'lib/lax/tree.rb', line 16

def with(*args,&b)
  where({args: args},&b)
end

#with_block(blk = nil, &b) ⇒ Object



20
21
22
# File 'lib/lax/tree.rb', line 20

def with_block(blk=nil,&b)
  blk  ? where({blk: blk},&b)   : where(blk: b)
end