Absolutely.
Tomas
From: [email protected]
[mailto:[email protected]] On Behalf Of Brian G.
Sent: Thursday, July 22, 2010 11:50 AM
To: [email protected]
Subject: Re: [Ironruby-core] Why does attr_accessor create a property,
but method is just a method?
Awesome! Do you take patches from the community?
Thanks,
Brian
2010/7/22 Tomas M.
<[email protected]mailto:[email protected]>
Ability to mark an existing method (pair) as a “property” implementation
makes sense.
I’ve added it the feature list:
http://ironruby.codeplex.com/workitem/4920
Tomas
From:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Curt H.
Sent: Thursday, July 22, 2010 7:19 AM
To: [email protected]mailto:[email protected]
Subject: Re: [Ironruby-core] Why does attr_accessor create a property,
but method is just a method?
I don’t know that you should appreciate anything I say; I haven’t worked
on IronRuby in over a year. 
A long time ago, I wrote code for ICustomTypeDescriptor that does
property inference based on the presence of arity-0 “foo” and arity-1
“foo=” but I had assumed that WPF was now binding via IDMOP and not
ICustomTypeDescriptor. Since this doesn’t work via “dynamic”, I guess
that’s not the case. Maybe Tomáš has something to add?
From:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Brian G.
Sent: Thursday, July 22, 2010 7:10 AM
To: [email protected]mailto:[email protected]
Subject: Re: [Ironruby-core] Why does attr_accessor create a property,
but method is just a method?
No, that is not sufficient, because it does not work. Assuming the
example I posted, this code fails:
dynamic automatic = testObject.automatic;
dynamic manual = testObject.manual;
dynamic autoLength = automatic.Length;
dynamic manualLength = manual.Length; // RuntimeBinderException
manual.Length
fails because manual
is of type
IronRuby.Builtins.RubyMethod
and Length
is not defined.
This is my problem… since ‘manual’ is not exposed to .Net as a
property, it fails.
Brian
P.S. I REALLY appreciate you talking through this with me.
On Thu, Jul 22, 2010 at 10:01 AM, Curt H.
<[email protected]mailto:[email protected]> wrote:
WPF binds by effectively treating the Ruby object as “dynamic” - that
is, it goes through IDynamicMetaObjectProvider. You can get the same
behavior from C# by saying
dynamic obj = SomeRubyObject();
dynamic foo = obj.foo;
Is this not sufficient for your needs?
From:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Brian G.
Sent: Thursday, July 22, 2010 6:55 AM
To: [email protected]mailto:[email protected]
Subject: Re: [Ironruby-core] Why does attr_accessor create a property,
but method is just a method?
Thinking on this further, if there were some sort of interop-specific
class method… like attr_clr_property :foo, that caused any methods
named foo and foo=(var) to be visible to .Net as properties, that would
be sufficient.
Any thoughts on this?
B
On Thu, Jul 22, 2010 at 9:34 AM, Brian G.
<[email protected]mailto:[email protected]> wrote:
Curt,
Thank you very much for engaging 
Although I understand what you are saying, from an interop perspective,
this is not desirable.
In fact, the WPF binding system will see two methods (foo and foo=(val))
and determine that they are properties that can be bound to. C#, on the
other hand, can’t use them as properties. Furthermore, if I want a
simple side effect (like property change notification) in a property, it
makes sense for me to define my own foo and foo=(val) methods. Again,
WPF can get these notifications and read the “properties”, but C# just
sees methods. Another case might be where properties are just wrappers
around hashes… a case I am running into.
At a very minimum, I would expect to be able to create get_foo and
set_foo(value) in ruby to have them be seen as .Net properties, but this
doesn’t seem to work either.
In general, I am trying to understand good interop practices between my
ruby and C# and WPF code, but I can’t seem to make anything other than
attr_accessor work.
Brian
On Thu, Jul 22, 2010 at 9:17 AM, Curt H.
<[email protected]mailto:[email protected]> wrote:
I believe this works as designed.
The problem is that Ruby doesn’t otherwise distinguish syntactically
between a property and a method with no parameters. Imagine that you’re
in tooling such as Visual Studio. By default, the values of properties
are automatically displayed in the debugger and in tool tips. But if I
happen to have a no-args method named format_cdrive, I probably don’t
want that code to be run just to inspect its value. Effectively,
attr_accessor, attr_reader and attr_writer are used by IronRuby as
signals that indicate this operation is free of potentially-nasty side
effects.
From:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Brian G.
Sent: Thursday, July 22, 2010 5:49 AM
To: [email protected]mailto:[email protected]
Subject: Re: [Ironruby-core] Why does attr_accessor create a property,
but method is just a method?
So, I haven’t heard anything about this yet on Stack Overflow, or this
list.
Does anyone know if this is this a bug in IronRuby interop?
Thanks,
Brian
On Wed, Jul 21, 2010 at 12:34 PM, Brian G.
<[email protected]mailto:[email protected]> wrote:
This is a cross-post from Stack Overflow, but I haven’t heard a peep
there, so I figured I’d try here:
I am playing around with the interop between C# and IronRuby. I have
noticed that if I define a property in Ruby using attr_accessor
, it is
presented to C# as a property. If, on the other hand, I create the
exact same code manually, it comes back as a method.
For example, take this code:
var engine = IronRuby.Ruby.CreateEngine();
string script = @"
class Test
attr_accessor :automatic
def manual
@manual
end
def manual=(val)
@manual = val
end
def initialize
@automatic = ""testing""
@manual = ""testing""
end
end
Test.new
";
var testObject = engine.Execute(script);
var automatic = testObject.automatic;
var manual = testObject.manual;
When you look at the C# automatic
variable, the value is a string of
“testing”. If you look at the C# manual
variable, it is type
IronRuby.Builtins.RubyMethod.
Ultimately, I want to create my own properties in Ruby that can be used
in C#, but I can’t seem to make them be visible as properties like
attr_accessor
does.
I THINK, that there is some magic going on in the Module code of the
Ruby source code (ModuleOps.cs:DefineAccessor). Is there any way to do
this in Ruby code directly?
Thanks,
Brian
Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core