Sha256: e7764e51911bde6bec7a4f8dbac9e57ffd97b0e4e754094255dd9ab7f751735b

Contents?: true

Size: 902 Bytes

Versions: 11

Compression:

Stored size: 902 Bytes

Contents

require 'continuation' if RUBY_VERSION >= '1.9.0'

module ExtendIt
  module Caller
    # http://rubychallenger.blogspot.ru/2011/07/caller-binding.html
    refine Object do
      def caller_binding
        cc, count = nil, 0
        set_trace_func(lambda { |event, file, lineno, id, binding, klass|
          if count == 2
            set_trace_func nil
            cc.call(binding)
          elsif event == 'return'
            count += 1
          end
        })
        return callcc { |cont| cc = cont }
      end

      def caller_eval(str)
        cc, ok = nil, false
        set_trace_func(lambda { |event, file, lineno, id, binding, klass|
          if ok
            set_trace_func nil
            cc.call(binding)
          else
            ok = event == "return"
          end
        })
        return unless bb = callcc { |c| cc = c; nil }
        eval(str, bb)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
admin_it-1.0.11 lib/extend_it/caller.rb
admin_it-1.0.10 lib/extend_it/caller.rb
admin_it-1.0.9 lib/extend_it/caller.rb
admin_it-1.0.8 lib/extend_it/caller.rb
admin_it-1.0.7 lib/extend_it/caller.rb
admin_it-1.0.6 lib/extend_it/caller.rb
admin_it-1.0.5 lib/extend_it/caller.rb
admin_it-1.0.4 lib/extend_it/caller.rb
admin_it-1.0.3 lib/extend_it/caller.rb
admin_it-1.0.2 lib/extend_it/caller.rb
admin_it-1.0.1 lib/extend_it/caller.rb