literal
literal copied to clipboard
[Idea] Optional raise on shadow
A thought: how about adding an optional (as in configuration) raise if a prop reader/writer shadows an existing instance method on definition? Eg
class TestPropsRaiseWhenShadowing
def thingy
@stuff
end
def thingy=(stuff)
@stuff = stuff
end
prop :thingy, Integer # Boom, raises as reader defined
prop :thingy, Integer, reader: false, writer: :public # Boom, raises as writer
prop :thingy, Integer, reader: false, writer: false, # no raise
end
Obviously shadowing is always a possibility but thinking about when literal properties are used in library code where the end-user dev must inherit from some base and then add props, we can offer guard against accidentally shadowing base methods?
I think it makes sense to raise on shadow when the shadow is owned by the same class, but a really valid use of shadowing is to override a property from a super class.
I’d be up for looking at a PR, but I’m going to close this issue as I don’t think it’s something we need to do and issues to me represent TODOs.