Consider following C# program (ScriptService.SharedService provides
access to IronRuby and is unimportant for understanding the case):
----------------------------------------
using System;
using System.Diagnostics;
using Fi.Napa.Gui;
public class A
{
public string SomeField = "field";
public string SomeProperty { get { return "prop"; } }
public string SomeMethod() { return "method"; }
}
class Program
{
static void Main(string[] args)
{
ScriptService.SharedService.ExecuteStr(@"
def test(obj)
Debug::print 'In Ruby'
Debug::print obj.some_method
Debug::print obj.SomeMethod
Debug::print obj.send(:some_method)
Debug::print obj.send(:SomeMethod)
Debug::print obj.some_property
Debug::print obj.SomeProperty
Debug::print obj.send(:some_property)
Debug::print obj.send(:SomeProperty)
Debug::print obj.SomeField
Debug::print obj.some_field
Debug::print obj.send(:SomeField)
Debug::print obj.send(:some_field)
end
");
Action<object> test =
ScriptService.SharedService.ExecuteStr<Action<object>>("method(:test)");
try {
test(new A()); // Call the Ruby "test"-function with
instance of A as parameter
}
catch (Exception ex) { Debug.Print(ex.ToString()); }
}
}
----------------------------------------
Output of the program is:
In Ruby
method
method
method
method
prop
prop
prop
prop
field
field
A first chance exception of type 'System.ArgumentException' occurred in
Unknown Module.
System.ArgumentException: wrong number or type of arguments for
`SomeField'
at _stub_$27##27(Closure , CallSite , CodeContext , Object ,
RubyArray )
at _stub_MatchCaller(Object , CallSite , Object[] )
at System.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[]
args) in
C:\programs\IronRuby\trunk\src\Microsoft.Scripting.Core\Actions\CallSite
.cs:line 288
...
at System.Void(Object)(Object[] , Object )
at Program.Main(String[] args) in
C:\DATA\IronRubyIssueX\IronRubyIssueX\Program.cs:line 38
----------------------------------------
This indicates that CLR-class fields (unlike CLR-methods and
CLR-properties) cannot be accessed with ruby:s send-method although they
are directly accessible as ruby-methods:
Debug::print obj.SomeField # ok
Debug::print obj.some_field # ok
Debug::print obj.send(:SomeField) # Exception: wrong number of
arguments for method SomeField
Debug::print obj.send(:some_field) # Exception: wrong number of
arguments for method some_field
I would expect that in final IronRuby 1.0 CLR-interoperability the
syntaxes a.x and a.send(:x) would always work the same, regardless of a
and x. I assume this is the intention of IR team as well?
Also I am intrigued by the type of the exception: "wrong number or type
of arguments for `SomeField'". Does that indicate that the fields
*could* still be accessed with the send-method with some additional
arguments...?
Robert Brotherus
Software architect
Napa Ltd
Tammasaarenkatu 3, Helsinki FI-00180
P.O.Box 470, Helsinki FI-00181
Tel. +358 9 22 813 1
Direct. +358 9 22 813 611
GSM +358 45 11 456 02
Fax. +358 9 22 813 800
Email: [EMAIL PROTECTED]
www.napa.fi
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core