There is a current class conception in Ruby, according to Metaprogramming Ruby 2
Wherever you are in a Ruby program, you always have a current object: self. Likewise, you always have a current class (or module). As The Ruby interpreter always keeps a reference to the current class (or module), when you define a method, that method becomes an instance method of the current class.
And it changes with the class and module keyword.
When you open a class with the class keyword (or a module with the module keyword), that class becomes the current class.
So in your case, the current class of where run method defined is still RansackHelpers, but not RansackHelpers's singleton class.
Here it works,
module RansackHelpers class << self def split(attribute, model_class) def run(memo, model_class, attribute) # Code end run([], model_class, attribute) end end end
def self.run(memo, model_class, attribute)?runis nested toself.split, why do I have to add thatselfalso?runmethod?self.split. I have it mainly because I don't want to callself.splitwith fixed attributes, such as the[].