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

Fix #1348: global functions called during mount. #1351

Merged
merged 1 commit into from
Apr 7, 2016

Conversation

dblock
Copy link
Member

@dblock dblock commented Apr 6, 2016

Fixes #1348.

A globally defined def namespace in Ruby 2.3.0 pollutes OStruct instance methods. This is described in https://bugs.ruby-lang.org/issues/12136 and https://bugs.ruby-lang.org/issues/12251. One way to reproduce this is to include Rake::DSL in the global scope, which defines a global namespace method.

This PR gets rid of the OStruct. We cannot use a Hash here because we want to respond to methods like .index which are natively defined on a Hash, so we need a dummy structure that responds to anything. Because it behaves like a Hash though we don't need to register parameters or such, cc: @namusyaka in case I missed anything.

@dblock dblock force-pushed the global-namespace-function branch from 1d83032 to 5238f3a Compare April 6, 2016 19:14
@dblock dblock changed the title Bug: global functions called during mount, repro of #1348. Fix #1348: global functions called during mount. Apr 6, 2016
def namespace
attributes.namespace
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that a different implementation takes precedence over def_delegators.

@dblock dblock force-pushed the global-namespace-function branch from 5238f3a to 15a5acf Compare April 6, 2016 19:29
true
else
@attributes.key?(m)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to define respond_to_missing? for this class (https://robots.thoughtbot.com/always-define-respond-to-missing-when-overriding)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, fixed.

@dblock dblock force-pushed the global-namespace-function branch from 15a5acf to c887607 Compare April 7, 2016 10:49
@dblock dblock merged commit 05cd6f7 into ruby-grape:master Apr 7, 2016
@dblock dblock deleted the global-namespace-function branch April 11, 2016 18:12
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

Successfully merging this pull request may close these issues.

2 participants