Forum: IronRuby .Net<->IR Object Mapping

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Shay F. (Guest)
on 2009-06-08 20:27
Hi,

Is there a table somewhere defining how .Net objects are mapped to Ruby
objects?

Thanks,
Shay

----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Ivan P. (Guest)
on 2009-06-08 20:45
(Received via mailing list)
http://ironruby.net/Documentation/.NET/Names
http://ironruby.net/Documentation/.NET
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Shay F. (Guest)
on 2009-06-08 20:51
I meant more like namespaces turn to modules, interfaces to modules,
enums to...? constants to...?

I'll check it out now and write the results here.

Thanks for the reply!
Shay.

----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Jim D. (Guest)
on 2009-06-08 21:14
(Received via mailing list)
http://ironruby.net/Documentation/.NET/QA_Plan

There is a table there that covers most of these. Let me know if you
need something that isn't listed.

JD

...there is no try
Shay F. (Guest)
on 2009-06-08 21:57
The list on this page is great but it is not complete.

Here is what I came up with. Correct me if I'm mistaken:

.Net Object    Ruby Object
------------------------------------------------------
Namespace    Module
Interface    Module
Class      Class
Enum      Class
Enum constant    Class method
Constant    Class method
Static method    Class method
Property    Getter and setter methods
Public method    Instance method
Protected method  Instance method
Private method    Isn't mapped at all
Delegate    Class

I have to say that the delegate mapping is awesome!!!
I can't say why, but using it with a code block is much more fun than
writing anonymous methods or lambda expressions in C# :)

Thanks,
Shay.

----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Jim D. (Guest)
on 2009-06-08 22:14
(Received via mailing list)
Private method will map to a instance method, but only with
-X:PrivateBindings. Otherwise that looks great. Could I talk you into
updating the table and adding specs to
Merlin\Main\Languages\Ruby\Tests\Interop\net? Even just adding them to
uncategorized_spec.rb will work, I'll move them around.

Thanks,

JD

...there is no try
Shay F. (Guest)
on 2009-06-08 22:18
Sure. Just give me a few days.

I'll let you know when it's done.

Shay.
----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Jim D. (Guest)
on 2009-06-08 22:34
(Received via mailing list)
Thanks!

JD

...there is no try
Shri B. (Guest)
on 2009-06-08 22:55
(Received via mailing list)
With a build from the latest sources, the Cucumber C# example from
http://wiki.github.com/aslakhellesoy/cucumber/iron... is
working. Also, only two of the Cucumber tests fail. One seems to be a
test issue, and the other is because of
http://ironpython.codeplex.com/WorkItem/View.aspx?....
Please try out Cucumber and let us know what your experience is.

One usability issue is that Cucumber uses the win32console gem to
color-code the results it prints to the console, so that failures are in
red, etc. However, the win32console is a native gem and does not work
with IronRuby, and so you do not get colored output. It should be quite
easy to implement the win32console library in pure Ruby code (but marked
with platform="ironruby" as mentioned at
http://ironruby.net/Documentation/Real_Ruby_Applic...) using
the System.Console functionality. Anyone interested in doing this?

Shri
Seo S. (Guest)
on 2009-06-09 04:52
(Received via mailing list)
2009/6/9 Shri B. <removed_email_address@domain.invalid>:
> With a build from the latest sources, the Cucumber C# example from 
http://wiki.github.com/aslakhellesoy/cucumber/iron... is working. Also, only two 
of the Cucumber tests fail. One seems to be a test issue, and the other is because of 
http://ironpython.codeplex.com/WorkItem/View.aspx?.... Please try out 
Cucumber and let us know what your experience is.

Why is the issue filed on Iron*Python*?
Tomas M. (Guest)
on 2009-06-09 05:00
(Received via mailing list)
That's called dynamic language interop - Dino's fixing bugs in IronRuby
:))

I've filled it under IronRuby:
http://ironruby.codeplex.com/WorkItem/View.aspx?Wo...

Tomas
Shri B. (Guest)
on 2009-06-09 10:00
(Received via mailing list)
My mistake :) It was not intentional.
Shay F. (Guest)
on 2009-06-09 14:33
By the way, even with "-X:PrivateBinding" I can't access private
members. Should it be done in a special way?

Thanks,
Shay.

----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Shay F. (Guest)
on 2009-06-09 14:35
It also seems like protected methods and internal classes are accessible
in IR just like they were public. Is it the correct behavior?

Thanks,
Shay.

----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Shay F. (Guest)
on 2009-06-09 14:51
My mistake - internal classes are accessible only with
-X:PrivateBinding. Protected methods are always accessible like public
methods.

----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Tomas M. (Guest)
on 2009-06-09 19:11
(Received via mailing list)
Could you give an example where it doesn't work?

Tomas
Tomas M. (Guest)
on 2009-06-09 19:30
(Received via mailing list)
They are only accessible if called with a receiver that is an instance
of a derived class.
Or do you observe another behavior?

Tomas
Shay F. (Guest)
on 2009-06-09 19:38
I assumed a reflection like behavior... For example, doing something
like:
klass.method(:MyPrivateClrMethod).call

Can you write a simple example of what you've described?

Thanks,
Shay.

----------------------------
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Jim D. (Guest)
on 2009-06-09 20:22
(Received via mailing list)
That should work:

[302] > rbr
IronRuby 0.5.0.0 on .NET 2.0.50727.4918
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require 'fixtures.generated'
=> true
>>> c = ClassWithMethods.new
=> ClassWithMethods
>>> c.private_method
:0: undefined method `private_method' for
ClassWithMethods:ClassWithMethods (NoMethodError)

>>> c.private_methods
=> ["initialize", "`", "abort", "Array", "at_exit", "autoload",
"autoload?", "binding", "block_given?", "caller", "catch", "eval",
"exec", "exit", "exit!", "fail", "Float", "format", "getc", "gets",
"global_variables", "initialize_copy", "Integer", "iterator?", "lambda",
"load", "load_assembly", "local_variables", "loop", "method_missing",
"open", "p", "print", "printf", "proc", "putc", "puts", "raise", "rand",
"remove_instance_variable", "require", "select", "set_trace_func",
"singleton_method_added", "singleton_method_removed",
"singleton_method_undefined", "sleep", "sprintf", "String", "system",
"throw", "trap", "warn"]
>>> c.method(:private_method)
:0:in `method': undefined method `private_method' for class
`ClassWithMethods' (NameError)
        from :0

>>> exit
C:\vsl\Merlin\Main\Languages\Ruby\Tests\Interop\net
[303] > rbr "-X:PrivateBinding"
IronRuby 0.5.0.0 on .NET 2.0.50727.4918
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require 'fixtures.generated'
=> true
>>> c = ClassWithMethods.new
=> ClassWithMethods
>>> c.private_method
=> 'private'
>>> c.private_methods
=> ["initialize", "`", "abort", "Array", "at_exit", "autoload",
"autoload?", "binding", "block_given?", "caller", "catch", "eval",
"exec", "exit", "exit!", "fail", "Float", "format", "getc", "gets",
"global_variables", "initialize_copy", "Integer", "iterator?", "lambda",
"load", "load_assembly", "local_variables", "loop", "method_missing",
"open", "p", "print", "printf", "proc", "putc", "puts", "raise", "rand",
"remove_instance_variable", "require", "select", "set_trace_func",
"singleton_method_added", "singleton_method_removed",
"singleton_method_undefined", "sleep", "sprintf", "String", "system",
"throw", "trap", "warn"]
>>> c.method(:private_method)
=> #<Method: ClassWithMethods#private_method>
>>> c.method(:private_method).call
=> 'private'
>>> c.method(:private_method)[]
=> 'private'
>>> exit
C:\vsl\Merlin\Main\Languages\Ruby\Tests\Interop\net
[304] >


If you want to try with this class, it is defined in the
fixtures.generated.dll assembly in
Merlin\Main\Languages\Ruby\Tests\Interop\net

Thanks,
JD

...there is no try
Shay F. (Guest)
on 2009-06-10 01:05
I can't get it to work... What am I doing wrong?

This is my C# code:
namespace IRTests
{
  public class IRTest
  {
    private void MyMethod() {
      Console.WriteLine("Hi from C#");
    }
  }
}

And this is the IR console:

>>> t = IRTests::IRTest.new
=> IRTests.IRTest
>>> t.my_method
:0: undefined method `my_method' for IRTests.IRTest:IRTests::IRTest
(NoMethodError)

>>> t.method(:my_method)
D:\IronRuby\GitRepository\ironruby\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTED\Builtins\KernelOps.cs:1437:in
`method': undefined method `my_method' for class `IRTests::IRTest'
(NameError)        from :0

Thanks!
Shay.
----------------------------
Shay F.
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Jim D. (Guest)
on 2009-06-10 01:44
(Received via mailing list)
Works just fine for me. How are you starting up the console? Here's my
method:
[201] > ir -X:PrivateBinding
IronRuby 0.5.0.0 on .NET 2.0.50727.4918
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require 'temp1'
=> true
>>> IRTests::IRTest.new.my_method
Hi from C#
=> nil
>>>

JD

...there is no try
Shay F. (Guest)
on 2009-06-10 08:25
I had an old version (3-4 week old). After I got the latest source and
compiles it really works. Sorry for that.

Thanks!
Shay.
Will G. (Guest)
on 2009-06-14 09:49
(Received via mailing list)
I just wrote up a blog post detailing, step by step, the process I
followed
to get Cucumber working with IronRuby. May be old hat to some of you,
but I
figured that documenting my process might help others going forward.

http://hotgazpacho.org/2009/06/cucumber-and-ironru...
Jimmy S. (Guest)
on 2009-06-14 22:46
(Received via mailing list)
Thanks for the post! It will be very useful to people wanting to use it.
Mind if I put something similar on the “Real Ruby applications and
libraries” page?
http://ironruby.net/Documentation/Real_Ruby_Applications

I have comment about the last section:
SUPER IMPORTANT NOTE!
Any time you rebuild IronRuby, the C# compiler will erase the contents
of the directory C:\Development\IronRuby\Merlin\Main\Bin\Debug. This
includes the cucumber and cucumber.bat files. The only way I know to
rectify this is to igem install -–no-rdoc -–no-ri cucumber once again.
To avoid doing this, just have people create the cucumber.bat/cucumber
files in Merlin/Main/Languages/Ruby/Scripts/bin, where all the other
files like that are (rails.bat, rake.bat, etc). I believe that directory
already copies to a build’s $(TargetDir), but if not you can either just
add it to the path or make it copy.

~js

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Will G.
Sent: Saturday, June 13, 2009 10:48 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] Cucumber status

I just wrote up a blog post detailing, step by step, the process I
followed to get Cucumber working with IronRuby. May be old hat to some
of you, but I figured that documenting my process might help others
going forward.

http://hotgazpacho.org/2009/06/cucumber-and-ironru...

--
Will G.
http://willgreen.mp/
Will G. (Guest)
on 2009-06-14 23:29
(Received via mailing list)
My pleasure! I hope others will find the guide helpful. Pleas feel
free to link to the post and publicize it any way you see fit.

As for the cucumber executables (cucumber & cucumber.bat), or any gem
that installs executable commands, these files are installed by the
gem command, by default, in the same directory as the ruby executable.
Perhaps some combination of setting GEM_HOME and GEM_PATH could allow
them to be installed elsewhere? My RubyGems-foo is not yet advanced
enough.

I would hate for this to be a manual process for every gem install,
every time you rebuild IronRuby. I'm open to suggestions on automating
this, and ammending the post.

--
Will G.
http://willgreen.mp/



On Jun 14, 2009, at 2:42 PM, Jimmy S.
<removed_email_address@domain.invalid
Will G. (Guest)
on 2009-06-20 18:04
(Received via mailing list)
Shri,
I am very interested in using cucumber for my .Net projects, so I'm
willing
to give it a go at porting win32console. To that end, I've created a git
repo for it on GitHub:
http://github.com/hotgazpacho/ironruby-win32console

Any guidance anyone can offer would be appreciated. Thanks!

--
Will G.
http://willgreen.mp/
This topic is locked and can not be replied to.