Using methods in /lib while in script/console session


#1

While I’m in a script/console session I want access to methods I’ve
defined in a utilities unit I’ve put in the project/lib directory. I’ve
tried requiring the unit and loading the unit but still don’t get the
methods. What’s the technique to use in this case?


#2

On Oct 22, 5:15 pm, John S. removed_email_address@domain.invalid
wrote:

While I’m in a script/console session I want access to methods I’ve
defined in a utilities unit I’ve put in the project/lib directory. I’ve
tried requiring the unit and loading the unit but still don’t get the
methods. What’s the technique to use in this case?

Posted viahttp://www.ruby-forum.com/.

Put them into a module.
For instance, I have lib/image_handler.rb.
module ImageHandler
def self.foo
puts ‘foo’
end
class Image

end

end

$ script/console
Loading development environment (Rails 2.0.2)

ImageHandler
=> ImageHandler

ImageHandler::Image
=> ImageHandler::Image

ImageHandler.foo
=> “foo”


Daniel B.


#3

Daniel B. wrote:

Put them into a module.
For instance, I have lib/image_handler.rb.
module ImageHandler
def self.foo
puts ‘foo’
end
class Image

end

end

Daniel

Ok thanks that worked.

John S.