There seems to be an issue with a combination of public_send() (or send()) and
method_missing() when trying to call a method named "warn". The issue appears
with JRuby, but not when running the same code in Ruby from the command line.
First, the test case:
@Test
public void shouldRunFine() {
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet(
"class Me \n" +
"def method_missing(method_name, *args, &block) \n" +
"puts \"you have called: #{method_name}\" \n" +
"end \n" +
"end \n" +
"m = Me.new \n" +
"m.public_send(:info) \n" +
"m.public_send(:blah) \n" +
"# problem happens just here: \n" +
"m.public_send(:warn) \n"
);
}
{/code}
As above the code throws an exception on last line, output:
------------- Standard Output ---------------
you have called: info
you have called: blah
------------- ---------------- ---------------
------------- Standard Error -----------------
ArgumentError: wrong number of arguments calling `warn` (0 for 1)
_send_ at org/jruby/RubyBasicObject.java:1667
send at org/jruby/RubyKernel.java:2060
(root) at <script>:10
------------- ---------------- ---------------
Testcase: shouldRunFine(org.magnepath.general.RubyCallerTest): Caused an ERROR
(ArgumentError) wrong number of arguments calling `warn` (0 for 1)
org.jruby.embed.EvalFailedException: (ArgumentError) wrong number of arguments calling `warn` (0 for 1)
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133)
at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1264)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1257)
at org.magnepath.general.RubyCallerTest.shouldRunFine(RubyCallerTest.java:80)
Caused by: org.jruby.exceptions.RaiseException: (ArgumentError) wrong number of arguments calling `warn` (0 for 1)
at org.jruby.RubyBasicObject._send_(org/jruby/RubyBasicObject.java:1667)
at org.jruby.RubyKernel.send(org/jruby/RubyKernel.java:2060)
at RUBY.(root)(<script>:10)
{/noformat}
which seems to suggest their is a private :warn method on Class with 1 argument?
Meanwhile, if I run the equivalent code as below
class Me
def method_missing(method_name, *args, &block)
puts "you have called: #{method_name}"
end
end
m = Me.new
m.public_send(:info)
m.public_send(:blah)
m.public_send(:warn)
{/noformat}
against Ruby on the command-line, I get the following output with no errors:
you have called: info
you have called: blah
you have called: warn{/noformat}
The version of ruby installed on my system is:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
{/noformat}
|