active-hash / active-hash/active_hash
GOTCHA - Cannot use the field name 'display' in ActiveHash as Rails adds it to Object class
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.4k
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ActiveHash::Base and the field declaration for display, then trace the method-generation guard against existing instance methods. Determine whether a warning or error is appropriate for the collision and add coverage showing that the conflict is reported instead of silently returning nil.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100