Search code examples
ruby-on-railsrubypathname

What is the meaning of '{**}' in Pathname#join


In my Rails project in application.rb file there is a line, which is written by some previous developer who was working on the project.

config.autoload_paths += Dir[Rails.root.join('app', 'classes', '{**}')]

I know that autoload_paths is used by rails to load all required files. I am not able to figure out the meaning of {**}. Does this means all files and sub directories of classes directory will be loaded? Is there any documentation which I can refer for this.

I have done some debugging.

2.2.5 :008 > Rails.root.join('app', 'classes', '{**}')
 => #<Pathname:/home/tk/src/project-name/app/classes/{**}> 

This is actually a Pathname object. But I have not found any reference about {**} here.

Does any one have any idea what is {**}? Is there any documentation for this?


Solution

  • Pathname just builds a path, it does not care about parts.

    ** is a parameter to Dir#[] which is eventually an alias to Dir#glob.

    ** means “match directories recursively.”