I tried to ask this question once in Ruby-talk and inside another post in
this list. No one answered me and I doubt anyone is able to answer it.
So, I tried changing the subject in a weird, although correct question, to
see if someone could help me.
In actionpack/lib/action_view/paths.rb, there is the following snippet:
def templates_in_path
(Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")).each do |file|
unless File.directory?(file)
yield Template.new(file.split("#{self}/").last, self)
end
end
end
That got me intrigued. What is the difference between
Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")
and just
Dir.glob("#{@path}/**")
?
Thanks, Rodrigo.
I tried to ask this question once in Ruby-talk and inside another
post in
this list. No one answered me and I doubt anyone is able to answer it.
So, I tried changing the subject in a weird, although correct
question, to
see if someone could help me.
In actionpack/lib/action_view/paths.rb, there is the following
snippet:
def templates_in_path
(Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")).each do |
file>
unless File.directory?(file)
yield Template.new(file.split("#{self}/").last, self)
end
end
end
That got me intrigued. What is the difference between
Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")
and just
Did you try running them ? Two minutes in the console seems to
indicate that "#{@path}/**/*/**" matches files inside those folders as
many levels down as you want
whereas "#{@path}/** just lists those folders in @path
Fred
Frederick Cheung wrote:
I tried to ask this question once in Ruby-talk and inside another
post in
this list. No one answered me and I doubt anyone is able to answer it.
So, I tried changing the subject in a weird, although correct
question, to
see if someone could help me.
In actionpack/lib/action_view/paths.rb, there is the following
snippet:
def templates_in_path
(Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")).each do |
file>
unless File.directory?(file)
yield Template.new(file.split("#{self}/").last, self)
end
end
end
That got me intrigued. What is the difference between
Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")
and just
Did you try running them ? Two minutes in the console seems to
indicate that "#{@path}/**/*/**" matches files inside those folders as
many levels down as you want
whereas "#{@path}/** just lists those folders in @path
Fred
Ok, I got, they are different. But playing a bit more with glob, I found out
that (or, at least, it seems to):
Dir.glob("#{@path}/**") == Dir.glob("#{@path}/*")
and
(Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")) ==
(Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/*")) ==
Dir.glob("#{@path}/**/*")
Except for order. To be sure, try this:
(Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/*")).sort ==
Dir.glob("#{@path}/**/*")Dir.glob("#{@path}/**/*").sort
So, I would change my question:
Wouldn't
Dir.glob("#{@path}/**/*")
be a better replacement to
Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")
?
Rodrigo.