This project is archived and is in readonly mode.
attr_accessor_with_default with collections
Reported by parrish | March 1st, 2011 @ 07:14 PM
I started digging into this when I stumbled across this SO
question: http://stackoverflow.com/questions/3481406
To give an example of the unexpected behavior:
class Container
attr_accessor_with_default :foo, [0, 0]
end
# This works as expected
c = Container.new
c.foo = ["foo", "bar"] # => ["foo", "bar"]
Container.new.foo # => [0, 0]
c.foo[0] = 0 # => [0, "bar"]
Container.new.foo # => [0, 0]
# This changes the class default value
c2 = Container.new
c2.foo # => [0, 0]
c2.foo[0] = "problem!" # => ["problem!", 0]
Container.new.foo # => ["problem!", 0]
I'll be submitting a patch shortly.
Comments and changes to this ticket
-
parrish March 1st, 2011 @ 07:24 PM
I'm sure there is a more elegant approach to this, but I couldn't think of a simpler one that maintained scopes correctly.
Refactoring suggestions are welcome :)Discarding the block option would definitely clarify the intent and code in this method, but that's just my two cents.
-
parrish March 1st, 2011 @ 07:28 PM
- Tag changed from activesupport, core_ext, module to activesupport, core_ext, module, patch
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>