> %w(action_controller/railtie action_mailer/railtie).map &method(:require)
=> [true, true]
And method call returns an instance of Method.
> method(:require)
=> #<Method: Object(Kernel)#require>
So there has to be a to_proc definition in method and it should be something like
class Method
def to_proc
proc { |obj| self.send(obj) }
end
end
My question is does rails override this to_proc in Method or what.
why following command is behaving the way it is behaving
> %w(action_controller/railtie action_mailer/railtie).map &method(:require)
=> [true, true]
method#to_procreturns something that, when you callcallon it, the method, passing the supplied arguments. For exampleoutputs hello world. That method “remembers” where it came from, in this case your script’s top level object. Methods like
puts,requireare define (via Kernel) on Object, so it doesn’t really matter what object the method is bound to (assuming of course that class doesn’t define its own require method!)So
%w(action_controller/railtie action_mailer/railtie).map &method(:require)is equivalent to calling require passing in those strings one at a time and collecting the return value(which happens to betrue– don’t pay too much attention to the return value of require.This is not a rails thing – you could do exactly the same thing in a vanilla irb session with any files available to be required. I’m not I would do this – it strikes me as choosing ‘cute’ over ‘understandable’.