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

Macro ancestors #3875

Merged
merged 1 commit into from Mar 28, 2017
Merged

Macro ancestors #3875

merged 1 commit into from Mar 28, 2017

Conversation

david50407
Copy link
Contributor

Solved #3871 .

After this PR, we can use #ancestors and #superclasses in macro to get the inherit chain of the type.

class Foo
  def self.ancestors
    {{@type.ancestors}}
  end
  def self.superclasses # returns all superclass (without includes)
    {{@type.superclasses}}
  end
end

module Bar; end
class FooBar < Foo
  include Bar
end

puts FooBar.ancestors #=> [Bar, Foo, Reference, Class]
puts FooBar.superclasses #=> [Foo, Reference, Class]

superclasses << klass
end
superclasses
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, I don't know if add #superclasses here is okay because this is useless in the whole compiler...
Or maybe this should just go into src/compiler/crystal/macros/methods.cr (or I can just drop this commit of #superclasses)

Copy link
Contributor

Choose a reason for hiding this comment

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

We already have superclass, I'm not sure we need superclasses —which doesn't exist in Ruby, by the way. Both for the compiler (not used) and for @type. We can already iterate from parent to parent if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ysbaddaden ok then I'm going to remove the commit of superclasses, thanks for reviewing 😄

@david50407 david50407 changed the title Macro ancestors Macro ancestors/superclasses Jan 12, 2017
@david50407 david50407 changed the title Macro ancestors/superclasses Macro ancestors Jan 12, 2017
@david50407
Copy link
Contributor Author

@ysbaddaden I removed the superclasses part 🎉

Copy link
Member

@bcardiff bcardiff left a comment

Choose a reason for hiding this comment

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

We would need some docs here https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/macros.cr#L1466 so they are published at crystal api

@david50407
Copy link
Contributor Author

@bcardiff updated. thanks 😄

@Sija
Copy link
Contributor

Sija commented Mar 24, 2017

Is this PR GTG?

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.

None yet

5 participants