-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Delegation method bug #10347
Delegation method bug #10347
Conversation
# @bar = bar | ||
# end | ||
# | ||
# delegate :name, ro: :@bar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo - should be to: :@bar
@lellisga thanks for this! |
@pixeltrix thanks to you. This is ready |
@@ -171,6 +171,11 @@ def test_delegation_with_allow_nil_and_nil_value | |||
assert_nil rails.name | |||
end | |||
|
|||
def test_delegation_with_allow_nil_and_invalid_value | |||
rails = Project.new("Rails", "David") | |||
assert_raise(NoMethodError) { rails.name } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix indentation here 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guille <3 <3 u didn't ping me "faltón" 👎
Add documentation and test to delegation method that make sure we're aware that when a delegated object is not nil or false and doesn't respond to the method it will still raise a NoMethodError exception.
Followup: see my comment here. |
… true, and avoids multiple evaluation of the target method Notes: 1) I hope nilness is a word. 2) See rationale for avoiding multiple evaluation in a comment in the patch, credit goes to @jeremy for pointing out this gotcha in the existing implementation. 3) Embeds a little joke dedicated to @pixeltrix (it could be worse! :D). References #10347.
Add documentation and test to delegation method that make sure we're
aware that when a delegated object is not nil or false and doesn't
respond to the method it will still raise a NoMethodError exception.