Closed dblock closed 6 years ago
That is the solution when there is another library that is polluting global scope. It could be changed by modifying the mk_binfile
method in scaffold.rb
(and requisite docs).
FWIW I just ran into this, and pretty sure I wasn't polluting the global scope. I was calling .version
on an OpenStruct
that had a version
key, and instead somehow it ended up calling what looked like the GLI version
directive, and therefore crashing.
I got around it by doing as OP suggested and making the GLI::App
extend inside a dummy class.
If you included GLI::App
at the top level of your main file, then all of GLI's methods get defined there, which is on Object
. That means that in this case, the method version
got added to Object
and since OpenStruct
inherits from object, it will have that method defined. Not sure how OpenStruct
is implemented, but it's likely that it will not override a method that's already defined, so it sees version
defined and thus doesn't define its own for the data inside itself.
Yeah that's what I suspected. I was just following the GLI docs website to get up and running at first, so maybe that needs to be updated to show using the dummy class instead, so people don't run into this issue out the gate. I mean it all makes sense if you sit and think it through, but when you're trying to get something done quickly the lizard brain is happy to see and do :)
Thanks for GLI!
PS. Happy to submit PR to the pages branch with that kind of update if you think its appropriate
That was in https://github.com/davetron5000/gli/pull/278/files, no? Maybe the website needs to be pushed?
Yeah, http://davetron5000.github.io/gli/ doesn't show those changes.
Ahhhh! Yeah, I've now updated the gh-pages for this so the example shows using a namespacve.
Coming from https://github.com/rmosolgo/graphql-ruby/issues/1775. I might not understand the issue completely.
The documentation suggests to
include GLI::App
in global scope. This caused the graphql-ruby gem to call GLI'sarguments
method as I believe it extends Object (still debugging this one). An easy workaround is to place the GLI code into a class as seen here.Should this be the recommended way of doing things?