This project is archived and is in readonly mode.

#6496 new
parrish

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

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>

People watching this ticket

Attachments

Pages