[Ironruby-core] Calling a C# static from IronRuby

Ivan Porto Carrero ivan at flanders.co.nz
Fri Nov 13 15:29:39 EST 2009


My 2c on the matter

I think Ruby on .NET is great and stuff like the clr_new, overloads etc are
a necessary evil to ease working with CLR classes.
But I do think that changing a basic construct like include will not be good
unless the other rubies also include it. The reason for it is you only use
clr_new (which is aptly prefixed btw) or overload etc when you're working
with the CLR but include you use in other implementations too and then it
won't behave consistently across the board.


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



On Fri, Nov 13, 2009 at 9:07 PM, Jimmy Schementi <
Jimmy.Schementi at microsoft.com> wrote:

> FYI, we’re thinking about allowing you to use “include” with .NET types,
> which will include it’s static methods. That would enable:
>
>
>
> include MyCSharpClass
>
> puts mymethod "foo"
>
>
>
> IronPython already does this for import, so it seems like a good idea:
>
>
>
> from MyCSharpClass import mymethod
>
> print mymethod("foo")
>
>
>
> ~Jimmy
>
>
>
> *From:* ironruby-core-bounces at rubyforge.org [mailto:
> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Ivan Porto Carrero
> *Sent:* Friday, November 13, 2009 11:04 AM
> *To:* ironruby-core at rubyforge.org
> *Subject:* Re: [Ironruby-core] Calling a C# static from IronRuby
>
>
>
> You can only reach it by adding the class as receiver.
>
>
>
> but you can use method missing as a dispatcher:
>
>
>
> alias :old_mm :method_missing
>
> def method_missing(method_name, *args, &block)
>
>    return MyCSharpClass.send(method_name, *args) if MyCSharpClass.respond_to?
> method_name
>
>    old_mn method_name, *args, &block
>
>  end
>
>
>
>
>
>
>
> try this in a console :)
>
>
>
> alias :old_mm :method_missing
>
> def method_missing(method_name, *args, &block)
>
>    return System::Math.send(method_name, *args) if System::Math.respond_to?
> method_name
>
>    old_mn method_name, *args, &block
>
>  end
>
>
>
> puts pi
>
> ---
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> Blog: http://flanders.co.nz
> Google Wave: portocarrero.ivan at googlewave.com
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
>
>
> On Fri, Nov 13, 2009 at 7:22 PM, Alexandre Mutel <lists at ruby-forum.com>
> wrote:
>
> Hi all,
> Is there any way to declare a C# static method accessible from IronRuby
> as a regular Ruby method?
> like:
> public class MyCSharpClass {
>  public static string mymethod(string test) {
>     return test + "yes";
>  }
> }
>
> in ironruby:
> puts mymethod("test")
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> 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/20091113/9b5429aa/attachment.html>


More information about the Ironruby-core mailing list