Crystal lang : method_missing for class object?
Clash Royale CLAN TAG#URR8PPP
Crystal lang : method_missing for class object?
Something like this?
class A
module ClassMethods
macro method_missing(call)
% p call %
end
end
extend ClassMethods
end
A.a
Result of the code is Error : undefined method 'a' for A:Class
. It seems method_missing
doesn't work for class object.
Error : undefined method 'a' for A:Class
method_missing
The reason for the question is that I implemented a class with a current
class method to get an instance for current context. For the simplification, I want some like forward_missing_to
to replace MyClass.current.xxx
with MyClass.xxx
, so method_missing
is required according forward_missing_to
's implementation.
current
forward_missing_to
MyClass.current.xxx
MyClass.xxx
method_missing
forward_missing_to
I also found, delegate
works fine for class methods using above way. So actually my pratical problem has been solved, but I'm still interesting with the question : method_missing
for class object, is it impossible?
delegate
method_missing
method_missing
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
There's no way to do this right now. Also,
method_missing
is discouraged and I can imagine it being removed in the future.– asterite
Aug 13 at 18:27