2009/1/11 Phlip <phlip2005 / gmail.com>:
> Trans wrote:
>> Binding.of_caller is no longer possible.
>
> Is a workaround available?

It seems that the original idea of Florian Grois still valid. Here's
a version working for my Ruby 1.8.6 on Windows:

  ##
  #  Re-implementation of Binding.of_caller for Ruby 1.8.6
  #  (C) 2009 Pit Capitain
  #  Original idea and implementation by Florian Gross
  #
  def Binding.of_caller

    old_critical = Thread.critical
    Thread.critical = true

    restart_cc = result = error = nil

    expected_events = %w"line c-call c-return return return"
    tracer = lambda do |event, file, line, id, binding, classname|
      if expected_events.empty?
        set_trace_func(nil)
        result = binding
        restart_cc.call
      elsif event != expected_events.shift
        set_trace_func(nil)
        error =
          "Binding.of_caller used in non-method context" +
          " or trailing statements of method using it aren't in the block."
        restart_cc.call
      end
    end

    callcc { |cc| restart_cc = cc }

    if result
      yield(result)
    elsif error
      raise(ArgumentError, error)
    else
      set_trace_func(tracer)
    end

  ensure
    Thread.critical = old_critical
  end

Regards,
Pit