Bugfix: do not confuse Kernel#Array #145

Merged
merged 2 commits into from Mar 13, 2012

2 participants

@avdgaag

On Ruby 1.9.2 (and maybe earlier) Kernel#Array will choke on a decorator,
because it just invokes to_ary and to_a without using respond_to?
first, like it does in 1.9.3-p125.

As a work-around, make sure to not create a delegation method in
method_missing when the model will not respond to it anyway. The
decorator object will then behave like Kernel#Array expects it to.

See #115.

@avdgaag avdgaag Bugfix: do not confuse Kernel#Array
On 1.9.2 (and maybe earlier) Kernel#Array will choke on a decorator,
because it just invokes `to_ary` and `to_a` without using `respond_to?`
first, like it does in 1.9.3-p125.

As a work-around, make sure to not create a delegation method in
`method_missing` when the model will not respond to it anyway. The
decorator object will then behave like `Kernel#Array` expects it to.

See #115.
f6c2acf
@avdgaag

The exact workings of Kernel#Array are unclear to me, so I am not sure if there is a cleaner fix for this problem. This is a solution, but ideally, we want to use the existing re-reraising of NoMethodError to trigger Kernel#Array to do what it otherwise does when an object does not respond to to_ary or to_a methods.

@steveklabnik steveklabnik merged commit 89126e4 into drapergem:master Mar 13, 2012
@steveklabnik
drapergem member

I'm not sure there's a cleaner fix either, but the tests are passing, so I'm happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment