There is a code in ruby
Dir.glob("my_folder/*.rb").each { |r| require_relative r}
I almost understand but I want to be sure why is the code below not working
Dir.glob("my_folder/*.rb").each(&:require_relative)
due to error of NoMethodError: private method require_relative' called for "my_folder/one.rb":String
Is this because
Dir.glob("controllers/*.rb").each(&:require_relative)
is equal to
Dir.glob("controllers/*.rb").each{ |r| r.require_relative }
?
You are right, it is equivalent to
& calls
to_procon an object, in this case, a symbol, andSymbolimplements it and creates a new Proc, which does a call on the object.