up vote 0 down vote favorite
share [g+] share [fb]

I am trying to access top level method from the class definition in IronRuby scripts. Example:

def global_hi
  puts "hi"
end

class A
  def hi
    global_hi
  end
end

A.new.hi

The script executed in ScriptEngine throws a NoSuchMethodError. I tried to ran the same code in iirb.bat It seems to behave the way I expected, which calls global_hi method correctly. But when I tried it in ir.exe, it throws the exception as well.

I investigated a little more and found out in iirb:

irb(main):021:0> self.method(:global_hi)
=> #<Method: Object#global_hi>

and in ir.exe as well as script engine

>>> self.method(:global_hi)
=> #<Method: Object(#<Class:#<Object:0x0000058>>)#xx>

I know there is some difference between iirb and ir but not sure the logic behind them. Is there anyway to make the script behave like the one in iirb.exe?

Thanks!

link|improve this question
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.