Class: Binding

Inherits:
Object show all
Defined in:
lib/ron.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.-(*args) ⇒ Object Also known as: from_h



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}" #unlikely method name
  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

Instance Method Details

#to_hObject



340
341
342
343
344
345
346
347
# File 'lib/ron.rb', line 340

def to_h
  l=Kernel::eval "local_variables", self
  l<<"self"
  h={}
  l.each{|i| h[i.to_sym]=Kernel::eval i, self }
  h[:yield]=Kernel::eval "block_given? and proc{|*a__| #,&b__\n yield(*a__) #,&b__\n}", self
  h
end

#to_ron_list(session) ⇒ Object



393
394
395
396
397
# File 'lib/ron.rb', line 393

def to_ron_list session
  result=to_h.to_ron_list2(session).unshift("Binding-")
  result=["(",result,")"].flatten unless instance_variables.empty?
  result
end