NameError: uninitialized constant Stopwords
zackxu1 opened this issue · 6 comments
Hi.
I installed the stopwords-filter gem as suggested in the documentation.
Then I did in IRB:
stopwords = ['by', 'written', 'from']
filter = Stopwords::Filter.new stopwords
but I get error:
NameError: uninitialized constant Stopwords
How can I overcome this error?
Thanks
Zack
I solved this problem by typing, in IRB
require '~/.rvm/gems/ruby-1.9.3-p0/gems/stopwords-filter-0.2.1/lib/stopwords.rb'
which returns true
but with other gems I have installed, I didn't have to do this, the namespace is available automatically.
I wonder if there's something that can be done in the top-level stopwords.rb file to fix this.
Thanks
I will try to figure out why it doesn't autoinclude the gem.
Thanks!
Something is requiring filter.rb
directly. I'd either nest the definition, e.g.:
module Stopwords
class Filter
# ...
end
end
Or, more robustly, I'd require the parent from the child, e.g.:
require 'stopwords'
class Stopwords::Filter
# ...
end
I'm not quite sure I'm understanding the solution here (although I merged pull request #4 :P )
I'm trying the gem before publishing a new version. Prior to your fix I get in irb with bundle exec irb
. Typing Stopwords::Filter.new []
gives me an uninitialized constant Object::Stopwords
If I require the gem with require 'stopwords'
Then I get #<Stopwords::Filter:0x8f9c664 @stopwords=[]>
.
When I include your fix I have to do exactly the same. Or I keep getting the uninitialized constant Object::Stopwords
, but I don't get NameError: uninitialized constant Stopwords
in any case :(
I understand that the gem should autorequire if you are using bundle as it's specified in your gemfile, but I don't find any difference with the #4 pull request merged
Umm, what version of ruby are you running? I'm on 1.9.3
I think it's better to do
module ABC
class XYZ
...
end
end
this way, it creates module ABC even if ABC has never been created before
but if you do
class ABC::XYZ
..
end
it requires to know about ABC prior to executing this file.
For me, when I tried to use your gem method call, I got
NameError: uninitialized constant Stopwords
After the fix, the problem no longer occurred
Thanks for merging the fix.
Zack
On Sun, 7/7/13, brenes notifications@github.com wrote:
Subject: Re: [stopwords-filter] NameError: uninitialized constant Stopwords (#3)
To: "brenes/stopwords-filter" stopwords-filter@noreply.github.com
Cc: "Zack Xu" zackxu@yahoo.com
Date: Sunday, July 7, 2013, 6:24 PM
I'm not quite sure I'm
understanding the solution here (although I merged pull
request #4 :P )
I'm trying the gem before publishing a new version.
Prior to your fix I get in irb with bundle exec
irb. Typing Stopwords::Filter.new []
gives me an uninitialized constant
Object::Stopwords
If I require the gem with require
'stopwords' Then I get
#<Stopwords::Filter:0x8f9c664
@stopwords=[]>.
When I include your fix I have to do exactly the same. Or
I keep getting the uninitialized constant
Object::Stopwords, but I don't get
NameError: uninitialized constant Stopwords in
any case :(
I understand that the gem should autorequire if you are
using bundle as it's specified in your gemfile, but I
don't find any difference with the #4 pull request merged
—
Reply to this email directly or view
it on GitHub.