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 Gro=DF is 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 =3D Thread.critical
    Thread.critical =3D true

    restart_cc =3D result =3D error =3D nil

    expected_events =3D %w"line c-call c-return return return"
    tracer =3D lambda do |event, file, line, id, binding, classname|
      if expected_events.empty?
        set_trace_func(nil)
        result =3D binding
        restart_cc.call
      elsif event !=3D expected_events.shift
        set_trace_func(nil)
        error =3D
          "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 =3D cc }

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

  ensure
    Thread.critical =3D old_critical
  end

Regards,
Pit