[Ironruby-core] Why does attr_accessor create a property, but method is just a method?

Brian Genisio briangenisio at gmail.com
Fri Jul 23 21:54:36 EDT 2010


So, I was looking at a unit test in the IR source code:

IronRuby.Tests/Runtime/HostingTests.cs:CustomTypeDescriptor1()

It is interesting, because it implies that the getter/setter should be
implicit based on foo and foo= being defined.  The property is retrievable
and even settable via the ICustomTypeDescriptor.GetProperties().

It appears to me that this implicit property should also be be available via
the dynamic invocation without the need to declare it via prop_accessor.

Am I off base?
Brian

On Fri, Jul 23, 2010 at 2:43 PM, Jim Deville <jdeville at microsoft.com> wrote:

> I agree, I don't like the idea of doing something that conflicts with
> current Ruby standards.
>
> I do like the prop_getter idea though, but that is essentially what we are
> talking about with an interop class method. I also have written class
> methods to do the Boolean idea before. Look through my CP_Bugger source to
> see some examples.
>
> JD
>
> -----Original Message-----
> From: ironruby-core-bounces at rubyforge.org [mailto:
> ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek
> Sent: Friday, July 23, 2010 11:01 AM
> To: ironruby-core at rubyforge.org
> Subject: Re: [Ironruby-core] Why does attr_accessor create a property, but
> method is just a method?
>
> Unless CRuby implements properties I don't like introducing property
> "names" that are different from foo, foo= pattern. For now that's just not
> the Ruby way.
>
> Tomas
>
> -----Original Message-----
> From: ironruby-core-bounces at rubyforge.org [mailto:
> ironruby-core-bounces at rubyforge.org] On Behalf Of Jörg W Mittag
> Sent: Friday, July 23, 2010 9:16 AM
> To: ironruby-core at rubyforge.org
> Subject: Re: [Ironruby-core] Why does attr_accessor create a property, but
> method is just a method?
>
> Brian Genisio wrote:
> > It is a good idea, but I have tried this already, and it still fails.
>
> So did I :-)
>
> > By
> > re-defining the method after attr_accessor, you blow away whatever
> > magic happens that causes it to be a property at interop time.
> >
> > Unless... you are suggesting that this is how it SHOULD work.
>
> Yes, that's what I meant.
>
> > I think either approach makes sense.  A special interop class method
> > is nice because it is explicit.  Having method redefinition do the job
> > is nice because it doesn't require a special class method :)
> >
> > What does everyone else think?
>
> Actually, I believe both make sense. Having method redefinition not work
> simply violates at least *my* Principle of Least Astonishment, so it needs
> to be fixed anyway. But it alone is not enough: sometimes you might want to
> have different names for your .NET property and your Ruby methods. A good
> example might be a readonly boolean property:
>
>    prop_getter :isValid => :valid?
>    def valid?
>      @is_valid
>    end
>
> Actually, now that I think about it, what about just overloading
> `attr_accessor` and friends? In plain Ruby,
>
>    attr_reader :isValid => :valid?
>
> is illegal anyway. Together with working method redefinition, I believe
> this would cover all use cases, no?
>
> [Note: the risk is that at some time in the future, Ruby might allow this
> notation to have the getter/setter names decoupled from the instance
> variable names. Actually, now that I think about it, I might suggest that
> right now :-) It always bugged me that you cannot simply define boolean
> accessors because that would try to create a @valid?
> instance variable, which is illegal.]
>
> jwm
>
> _______________________________________________
> 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
>
> _______________________________________________
> 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/20100723/cff767ea/attachment-0001.html>


More information about the Ironruby-core mailing list