-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 Annotation#types, #vars, #methods #7274
Comments
Yes, this would allow me to just get a list of all methods that are tagged as a route action. Currently I am requiring the controller classes to inherit from a predefined class, then iterating over the subclasses of that parent class, then filtering the methods down to just ones with the annotation. This would be a bit cleaner, and allow the user to define their own inheritance structure. |
@Blacksmoke16 there is an alternative possible solution for your case: https://forum.crystal-lang.org/t/type-all-includers/254 |
@vladfaust What would your use case be for wanting an array of ALL methods/instance vars? Would it make more sense to do something like: annotation Foo
end
class Klass
@[Foo]
def one
1
end
@[Foo]
def two
2
end
def three
3
end
end
pp {{Klass.methods(Foo)}} # => [one, two] Where allow |
If #7648 (comment) works for types, do we still need this feature for instance / class variables and defs, or are there similar workarounds for them? |
@HertzDevil You can basically use the same workaround but with |
I also realized today that the workaround im used to using ( |
These methods would allow to iterate over all types/vars/methods which have the annotation, e.g:
/cc @Blacksmoke16, this could be useful in Athena, right?
I also can find it useful in ORM implementations.
The text was updated successfully, but these errors were encountered: