Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#caller returns `__send__' as one of the callers #603

Closed
lkfken opened this Issue Mar 25, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@lkfken
Copy link

commented Mar 25, 2013

require 'pp'

module A
  def method_from_a
    caller
  end
end

class C
  include A
  def method_from_c
    __send__(:method_from_a)
  end
end

pp C.new.method_from_c

The code above if run under MRI Ruby 1.9.3 or 2.0, the output is:

["X:/ene/RubyScripts/1development/debug_caller/caller.rb:12:in `method_from_c'",
 "X:/ene/RubyScripts/1development/debug_caller/caller.rb:16:in `<top (required)>'",
 "-e:1:in `load'",
 "-e:1:in `<main>'"]

If the code above is running under JRuby 1.7.3, the output is:

["X:/ene/RubyScripts/1development/debug_caller/caller.rb:12:in `__send__'",
 "X:/ene/RubyScripts/1development/debug_caller/caller.rb:12:in `method_from_c'",
 "X:/ene/RubyScripts/1development/debug_caller/caller.rb:16:in `(root)'",
 "-e:1:in `load'",
 "-e:1:in `(root)'"]

The output from MRI Ruby and JRuby are obviously different.

I could add some additional logic to my code using something like RUBY_PLATFORM to find the immediate caller, but isn't a compatibility issue for JRUBY?

@lkfken

This comment has been minimized.

Copy link
Author

commented Mar 25, 2013

Also, if I change the method to

...
module A
  def method_from_a(key = caller)
    key
  end
end
...

MRI Ruby (both 1.9.3 and 2.0) will produce the same output (as in previous example).
But JRuby will produce a different output.

["X:/ene/RubyScripts/1development/debug_caller/caller.rb:12:in `method_from_c'",
 "X:/ene/RubyScripts/1development/debug_caller/caller.rb:16:in `(root)'",
 "-e:1:in `load'",
 "-e:1:in `(root)'"]

and this is the same (well...not exactly if compare it word by word) output as in MRI Ruby 1.9.3 or 2.0.

So apparently, JRuby's #caller will not include #send as one of the callers if it is invoked at the parameter.

@BanzaiMan

This comment has been minimized.

Copy link
Member

commented Sep 3, 2013

On master, the output is:

["gh-603.rb:12:in `method_from_c'", "gh-603.rb:16:in `(root)'"]

@BanzaiMan BanzaiMan closed this Sep 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.