| Class | Recorder |
| In: |
lib/more/facets/recorder.rb
|
| Parent: | Object |
Recorder is similar essentially a method probe. It records everthing that happens to it, building an internal parse tree. You can then pass a substitute object and apply the recoding to it. Or you can utilize the parse tree.
The only limitation of Recorder is with special operators, like if, &&, ||, etc. Since they are not true methods they can‘t be recorded. (Too bad for Ruby.)
class Z
def name ; 'George' ; end
def age ; 12 ; end
end
z = Z.new
r = Recorder.new
q = proc { |x| (x.name == 'George') & (x.age > 10) }
x = q[r]
x.__call__(z)
produces
true
# File lib/more/facets/recorder.rb, line 91
91: def __call__( orig )
92: return orig unless @msg
93:
94: sym = @msg[0]
95: args = @msg[1..-1].collect do |a|
96: Recorder === a ? a.__call__(orig) : a
97: end
98: obj = args.shift
99:
100: obj.__send__( sym, *args )
101: end
# File lib/more/facets/recorder.rb, line 87
87: def inspect
88: "<Recorder #{@msg.inspect}>"
89: end