[Ironruby-core] more interop questions

Ivan Porto Carrero ivan at flanders.co.nz
Wed May 13 11:57:16 EDT 2009


Hi
I got into a discussion with Roy Osherhove about overriding statics.

I know in C# it can't be done obviously and as long as I stay in Ruby you
can. I understand this may seem like straight-forward stuff. Can you give me
a pointer where I can take stock of what I can and can't do to CLR objects
and in which cases ruby things apply?

But when you go back and call it from a C# class it takes the CLR
implementation

public class MyClassWithAStatic{

        public string HelloWorld(){
            return "Hello World!";
        }

        public static string GoodByeWorld(){
            return "Goodbye world!";
        }
    }

    public class StaticCaller{

        public string CallsStatic(){
            return MyClassWithAStatic.GoodByeWorld();
        }
    }

console session:
(master) » ir
IronRuby 0.4.0.0 on .NET 2.0.50727.4918
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require 'spec/bin/ClrModels.dll'
=> true
>>> include ClrModels
=> Object
>>> MyClassWithAStatic
=> ClrModels::MyClassWithAStatic
>>> MyClassWithAStatic.good_bye_world
=> 'Goodbye world!'
>>> sc = StaticCaller.new
=> ClrModels.StaticCaller
>>> sc.calls_static
=> 'Goodbye world!'
>>> class MyClassWithAStatic
... def self.good_bye_world
... "From Ruby we say goodbye to you"
... end
... end
=> nil
>>> MyClassWithAStatic.good_bye_world
=> "From Ruby we say goodbye to you"
>>> sc = StaticCaller.new
=> ClrModels.StaticCaller
>>> sc.calls_static
=> 'Goodbye world!'

New session to figure out if something could be done before the type was
actually created

+ C:\dev\caricature
(master) » ir
IronRuby 0.4.0.0 on .NET 2.0.50727.4918
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require 'spec/bin/ClrModels.dll'
=> true
>>> class MyClassWithAStatic
... def self.good_bye_world
... "From Ruby we say goodbye to you"
... end
... end
=> nil
>>> ClrModels::StaticCaller.new.calls_static
=> 'Goodbye world!'

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Don Marquis <http://www.brainyquote.com/quotes/authors/d/don_marquis.html>
- "Procrastination is the art of keeping up with yesterday."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090513/11663b36/attachment.html>


More information about the Ironruby-core mailing list