Fix nested attribute loading from anonymous classes under Ruby 1.9 #41

Merged
merged 1 commit into from Sep 18, 2012

Projects

None yet

2 participants

Contributor

In Ruby 1.8, anonymous classes have an empty string for a name. In Ruby 1.9, name is nil. This causes an error when loading nested attributes from an anonymous class as we determine its namespace. With this change, we'll stringify the name before we try to split it.

Why would you want to use anonymous classes like this? We use this pattern at 37signals to configure resource class options at runtime. For example, when requesting resources that are available at different hosts:

class User < ActiveResource::Base
  def self.on(account)
    Class.new(self).tap do |subclass|
      subclass.site = account.url
    end
  end
end

User.on(account).find(123)
@packagethief packagethief Fix nested attribute loading from anonymous classes under Ruby 1.9
In Ruby 1.8, anonymous classes have an empty string for a name. In Ruby 1.9, name is nil. This causes an error when loading nested attributes from an anonymous class as we determine its namespace. Stringify the name before we try to split it.
d98d012
@jeremy jeremy merged commit 6639bb4 into rails:master Sep 18, 2012

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment