Skip to content
Tags

,

Ruby Dir.glob ** pattern

June 12, 2013

I like to autoload all files in my app/model folder in my Rails app.

“config.autoload_paths accepts an array of paths from which Rails will autoload constants. Default is all directories under app.”

– Rails Guides

Now ruby docs for Dir.glob suggest using ‘**’ to match directories recursively. However, I notice that ‘**’ does not match any more or less files than ‘*’.

> Dir[Rails.root.join('app', 'models', '*')] == Dir[Rails.root.join('app', 'models', '**')]
 => true 

From this stack overflow post I got the idea of using ‘**/’ instead and that seems to work.

I am creating my simple cheatsheet here:

‘*’ – matches all files and directories in the current path
‘**’ – matches all files and directories in the current path
‘**/’ – matches all directories recursively in the current path
‘**/*’ – matches all files and directories recursively in the current path

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: