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

Add @top_level to access the top-level scope in macros #10682

Merged
merged 3 commits into from
May 12, 2021

Conversation

beta-ziliani
Copy link
Member

Fixes #8914 by creating a new instance method @top_level (as suggested by @jhass). This allows to query the top level module, as the following example shows:

FOO = 1
class Foo
   def bar
       {{@top_level.has_constant?("FOO")}}
    end
end

Co-authored-by: Ary Borenszweig <asterite@gmail.com>
Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@straight-shoota straight-shoota added this to the 1.1.0 milestone May 7, 2021
@straight-shoota straight-shoota changed the title Adding @top_level to access de program in macros Add @top_level to access the top-level scope in macros May 12, 2021
@straight-shoota straight-shoota merged commit 3b5bc55 into crystal-lang:master May 12, 2021
@straight-shoota
Copy link
Member

Gracias, @beta-ziliani

beta-ziliani added a commit to beta-ziliani/crystal that referenced this pull request Jul 23, 2021
straight-shoota pushed a commit that referenced this pull request Jul 23, 2021
straight-shoota pushed a commit that referenced this pull request Jul 24, 2021
straight-shoota pushed a commit that referenced this pull request Jul 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add top-level has_constant? macro method (or expose Program type)
3 participants