350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
# File 'lib/ron.rb', line 350
def -(*args)
h=args.first
return super unless ::Hash===h
h=h.dup
the_self=h.delete :self
the_block=(h.delete :yield) || nil
keys=h.keys
keys.empty? or
code=keys.map{|k|
k.to_s
}.join(',')+',=*Thread.current[:$__Ron__CaptureCtx]'
mname="Ron__capture_binding#{Thread.current.object_id}" oldmname=newmname=result=nil
eval "
newmname=class<<the_self;
mname=oldmname='#{mname}'
im=instance_methods
im.map!{|sym| sym.to_s} if Symbol===im.first
mname+='-' while im.include? mname
alias_method mname, oldmname if im.include? oldmname
def #{mname}
#{code}
binding
end
mname
end
"
Thread.current[:$__Ron__CaptureCtx]= h.values
result=the_self.send mname, &the_block
Thread.current[:$__Ron__CaptureCtx]=nil
class<<the_self;
self
end.send(*if newmname==mname
[:remove_method, mname]
else
[:alias_method, mname, oldmname]
end)
result
end
|