Rodrigo Rosenfeld Rosas
2008-Sep-09 13:27 UTC
(Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")) != Dir.glob("#{@path}/**") ?
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-09 13:39 UTC
Re: (Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")) != Dir.glob("#{@path}/**") ?
On 9 Sep 2008, at 14:27, Rodrigo Rosenfeld Rosas 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 justDid 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> > Dir.glob("#{@path}/**")> > ? > > Thanks, Rodrigo. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rodrigo Rosenfeld Rosas
2008-Sep-09 14:06 UTC
Re: (Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")) != Dir.glob("#{@path}/**") ?
Frederick Cheung wrote:> > > On 9 Sep 2008, at 14:27, Rodrigo Rosenfeld Rosas 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 > > FredOk, 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---