Re: [Rails-core] class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Jeremy Kemper
Hi Nick, On Fri, Jan 21, 2011 at 12:41 PM, Nick Sutterer wrote: > According to the docs, class_attribute does implement inheritance for > class instance variables. However, it doesn't work as it is intended > to, at least if you use "mutual structures", like Hash. > > Base.foo = {} > Subclass.foo

Re: [Rails-core] Re: class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Michael Koziarski
> Ouch - that's absolutely right. So worst case is > that in my solution you might still operate on a superclass object. > Let me think about that! We have several different options for this depending on the semantics you're after for your 'class variable things'. https://gith

[Rails-core] Re: class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Nick Sutterer
On 21 Jan., 22:27, Matt Jones wrote: > On Jan 21, 2011, at 3:41 PM, Nick Sutterer wrote: > > > By accident I solved this with a 10-liner months ago, why not use > > something like > > that?https://github.com/apotonick/hooks/blob/master/lib/hooks/inheritable_... > > > It's simple, clean and does

Re: [Rails-core] class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Matt Jones
On Jan 21, 2011, at 3:41 PM, Nick Sutterer wrote: > By accident I solved this with a 10-liner months ago, why not use > something like that? > https://github.com/apotonick/hooks/blob/master/lib/hooks/inheritable_attribute.rb > > It's simple, clean and does exactly what you expect. > Well, as

[Rails-core] Re: class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Nick Sutterer
> Please have a look also to the section about class inheritable attributes. > Do you basically say what I want is class_inheritable_hash ? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-

Re: [Rails-core] class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Xavier Noria
On Fri, Jan 21, 2011 at 9:41 PM, Nick Sutterer wrote: > According to the docs, class_attribute does implement inheritance for > class instance variables. However, it doesn't work as it is intended > to, at least if you use "mutual structures", like Hash. > > Base.foo = {} > Subclass.foo[:bar] = "

[Rails-core] Re: class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Nick Sutterer
> I'm sorry, but this is WRONG and dangerous. The docs tell me to "use > setters" here - not sure how this is supposed to work. > No offense meant - just like "somewhat less than perfect" ;-) > Another "solution" is to initialize the ivar in the subclass, again, > as done here:https://github.com/

[Rails-core] Re: class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Piotr Sarnacki
I like Nick's implementation, not everyone know or remembers that modyfing object like Hash or Array will also change the superclass (which is clearly visible in the commit that Nick's linked - that was exactly the reason of the bug that I was fixing). I think that it would be nice to have inherit

[Rails-core] class_attribute is too dangerous, here's an alternative

2011-01-21 Thread Nick Sutterer
According to the docs, class_attribute does implement inheritance for class instance variables. However, it doesn't work as it is intended to, at least if you use "mutual structures", like Hash. Base.foo = {} Subclass.foo[:bar] = "bar" Base.foo # => {:bar => "bar"} I'm sorry, but this is WRONG a