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

Support extend self by prototype rb #492

Merged
merged 1 commit into from
Nov 30, 2020

Conversation

pocke
Copy link
Member

@pocke pocke commented Nov 26, 2020

This pull request adds support for extend self by prototype rb.

For example, module M; extend self; end will be converted to module M; extend ::M; end. self that is in arguments of extend is converted to the module name in the current scope.

It converts self to an absolute type name. It means it always generates a full path as an argument of extend.
Because a relative path can be incorrect.
For example:

module M
  module M
  end

  # In this context, `extend M` means `extend ::M::M`,
  # so it should be converted to `extend ::M`.
  extend self
end

it can resolve include self with the same technique, but I didn't implement it because of meaningless.
include self raises an error, so actually no one uses this.

$ ruby -e module M; include self; end
-e:1:in `append_features': cyclic include detected (ArgumentError)
	from -e:1:in `include'
	from -e:1:in `<module:M>'
	from -e:1:in `<main>'

Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

💯

@soutaro soutaro merged commit 578324b into ruby:master Nov 30, 2020
@pocke pocke deleted the Support--extend-self--by-prototype-rb branch November 30, 2020 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants