[Ironruby-core] Access Top Level methods

Lewis Lin llin at polypaths.com
Wed Jul 20 10:49:00 EDT 2011


Thanks for the reply. My main development version is on 1.1 for .NET 
3.5. However, I did try it on 1.1.3 on .NET 4.0.30319.225 and still are 
able to reproduce the issue. I am running Windows XP 32bit environment. 
Is there any environment variables I should look into? Here is the 
screen copy I just did.

As far as I understand, the global environment is actually a 'main' 
Object. The function defined in the global scope should be translated to 
private method of Object class which is what it shows in iirb.bat. Not 
sure why ir.exe as well as the ScriptEngine behaves differently.

Thanks for your time!

c:\Program Files\IronRuby 1.1\bin>ir
IronRuby on .NET 4.0.30319.225
Copyright (c) Microsoft Corporation. All rights reserved.

 >>> def global_hi
... puts 'hi'
... end
=> nil
 >>> class A
...   def hi
...     global_hi
...   end
... end
=> nil
 >>> A.new.hi
(ir):3:in `hi': undefined method `global_hi' for #<A:0x0000056> 
         from (ir):1

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


c:\Program Files\IronRuby 1.1\bin>iirb
irb(main):001:0> def global_hi
irb(main):002:1>   puts 'hi'
irb(main):003:1> end
=> nil
irb(main):004:0> class A
irb(main):005:1>   def hi
irb(main):006:2>     global_hi
irb(main):007:2>   end
irb(main):008:1> end
=> nil
irb(main):009:0> A.new.hi
=> nil
irb(main):010:0> self.method(:global_hi)
=> #<Method: Object#global_hi>

On 7/20/2011 8:37 AM, Sickboy wrote:
> I cannot reproduce this issue with IronRuby on .NET 4.0.30319.235
> It works as expected: ir.exe result is same as irb result.
> Regards
> *From:* Lewis Lin <mailto:llin at polypaths.com>
> *Sent:* Thursday, June 30, 2011 9:58 PM
> *To:* ironruby-core at rubyforge.org <mailto:ironruby-core at rubyforge.org>
> *Subject:* [Ironruby-core] Access Top Level methods
> Hi,
> I am trying to access top level method from the class definition in 
> IronRuby scripts. Example:
> def global_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.exe It seems to behave the way I 
> expected. But when I tried it in ir.exe, it throws the exception as well.
> I investigate a little more and found out
> irb(main):021:0> self.method(:global_hi)
> => #<Method: Object#global_hi>
> and
> in ir.exe as well as script engine
> >>> self.method(:xx)
> => #<Method: Object(#<Class:#<Object:0x0000058>>)#xx>
> Is there anyway to make the script behave like the one in iirb.exe?
> Thanks,
> Lewis
> ------------------------------------------------------------------------
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20110720/d64ccb47/attachment.html>

More information about the Ironruby-core mailing list