Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GOTCHA - Cannot use the field name 'display' in ActiveHash as Rails adds it to Object class #184

Open
hunterae opened this issue Oct 9, 2019 · 0 comments

Comments

@hunterae
Copy link

hunterae commented Oct 9, 2019

I was attempting to use a field with name "display"; example:

class TestHash < ActiveHash::Base
  field :display, default: true
  add
  add display: false
end

However, ActiveHash defines method only if an existing instance method does not already exist, and Rails adds this method to either Object or Kernel. Ex:

TestHash.first.display
#<TestHash:0x00007f870c24a780> => nil
TestHash.last.display
#<TestHash:0x00007f870c249f38> => nil

While I totally understand the rationale here, I think it would be really helpful if you could spit out a warning or error if we attempt to define a method that is already defined. The result of the above issue was that most of my test suite failed and I had countless lines outputting the class information for individual ActiveHash records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant