C0 code coverage information
Generated on Mon Mar 10 10:31:09 -0500 2008 with rcov 0.8.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 # :main: README
2 module MethodChain
3
4 # send a method, evaluate a block, but always return self
5 def tap meth=nil, &block
6 __send__ meth if meth
7 yield_or_eval &block if block_given?
8 self
9 end
10
11 # method chaining with a guard.
12 # If no guard block is given then guard against nil and false
13 # *methods = [method] where
14 # method = Message | Code
15 # Message = Symbol | [Symbol, *arguments]
16 # Code.to_proc = Proc
17 def chain *methods, &guard
18 return self if methods.empty? or not(
19 (block_given? ? (yield_or_eval &guard) : self))
20
21 case(meth = methods.shift)
22 when Symbol then __send__ meth
23 when Array then __send__ *meth
24 else yield_or_eval &meth
25 end.chain(*methods, &guard)
26 end
27
28 # yield or eval based on the block arity
29 def yield_or_eval &block
30 case block.arity
31 # ruby bug for -1
32 when 0, -1 then instance_eval(&block)
33 when 1 then yield(self)
34 else raise ArgumentError, "too many arguments required by block"
35 end
36 end
37
38 # return self if self evaluates to false, otherwise
39 # evaluate the block or return the default argument
40 def then default=nil, &block
41 if self
42 block_given? ? (yield_or_eval &block) : (default || (fail \
43 ArgumentError, "#then must be called with an argument or a block"))
44 else
45 self
46 end
47 end
48
49 # the inverse of then
50 def else arg=nil, &block
51 if self
52 self
53 else
54 block_given? ? (yield_or_eval &block) : (arg || (fail \
55 ArgumentError, "#else must be called with an argument or a bloc"))
56 end
57 end
58 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.