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

[Idea] Optional raise on shadow #103

Open
stevegeek opened this issue Sep 7, 2024 · 1 comment
Open

[Idea] Optional raise on shadow #103

stevegeek opened this issue Sep 7, 2024 · 1 comment

Comments

@stevegeek
Copy link
Collaborator

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?

@joeldrapper
Copy link
Owner

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.

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

2 participants