I have a file under /lib with its own method.
# lib/file.rb
class File < ApplicationController
def my_method
...
end
end
However I can’t reach the method through the console
ruby-1.9.2-p290 :044 > File.my_method
NoMethodError: undefined method `my_method' for File:Class
Any idea how?
my_methodis an instance method of theFileclass. It means that you can call it only on the instance of theFileclass.You can declare
my_methodas class method usingdef self.my_methodsyntax.But in class methods you can’t use instance variables of the
Fileobject.