I'm new to Ruby, and there is a gem that I want to chat with the JSNRPC API and basically all Calls and responses are quite similar, that each API call can be handled with a function such as:
Module :: API_Order ('APINapspace.Namespace Math')
< / P>
But I also want to be able to (for convenience):
Module :: APIINA Space Namespace method
There is no reason to do this by using Module.const_missing to return a dummy class to a method_masing that is the module :: APINamespace.NamespaceMethod
to Module :: api_command ('APINamespace.NamespaceMethod') will allow the call to pass
Is there any more elegant or decent way to do this? ?
Yes, I'm sorry, but this is the hack in my mind ridiculous First of all, I'm assuming that your api_command method is actually implementing methods on the
APINamespace
module, as this line Contains: Module :: API_Order ('APINapspace.Namespace Method')
Looking at the above, why not include APINamespace
in your module Set equal steady?
MyModule :: APINamespace = :: APIspace MimeModule :: APIINS Space. Namespace Method ()
Update:
I still do not understand my position completely, but perhaps it is:
Module MyModule def self.const_missing (c) Object.const_get (c) End End
Now you can apply any top-level stability As if it was defined on your module; It is said that there was a module called StrangeAPI
at the top level, if you use the hack above, you can now implement its methods:
MyModule :: Strange API Blah ()
Do you want it?
Comments
Post a Comment