In irb, I do this
class Text
include FileUtils
end
I get: NameError: uninitialized constant Test::FileUtils
If I just do: include FileUtils (i.e. now class) everthing works.
What gives?
In irb, I do this
class Text
include FileUtils
end
I get: NameError: uninitialized constant Test::FileUtils
If I just do: include FileUtils (i.e. now class) everthing works.
What gives?
Did you try?
class Text
include ::FileUtils
end
This assumes that FileUtils is not within a module.
You need to make sure Ruby knows about the FileUtils module. That module isn't loaded by default:
>> FileUtils
NameError: uninitialized constant FileUtils
from (irb):1
>> require 'fileutils'
=> true
>> FileUtils
=> FileUtils
Don't worry too much about the error NameError: uninitialized constant Text::FileUtils
- when you try to include a constant that Ruby doesn't know about, it looks in a few places. In your case, first it will look for Text::FileUtils
and then it will look for ::FileUtils
in the root namespace. If it can't find it anywhere (which in your case it couldn't) then the error message will tell you the first place it looked.