In the book, "Agile Web Development With Rails" there is a simple idea for an example program using the command: @dirs = Dir.glob(''*'') Then they suggest writing the code to display the directory contents but don''t say how. So I wrote a file called app/views/say/dirlist.rb which has the following code: <html> <head> <title>Directory Listing</title> </head> <body> <h1>Directory:</h1> <p> <%= @dirs %> </p> </body> </html> The problem is that while all the file and directory names are displayed, they are also all "run together". What would be the easiest and most logical way to format the output so that the filenames are separated by ", "? --------------------------------- Get your own web address for just $1.99/1st yr. We''ll help. Yahoo! Small Business. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
well, you could do this (but I hate the trailing '','' that results ) <%= @dirs.collect { |dir| "#{dir}," } %> -------------------------------------------------- Peter Wright froogle-jY3Lu0o19T39IxVxf2VSKA@public.gmane.org Personal Blog -> http://peterwright.blogspot.com Agile Development Blog -> http://exceeding-expectations.blogspot.com On 6 Sep 2006, at 13:50, Arthur Baldwin wrote:> In the book, "Agile Web Development With Rails" there is a simple > idea for an example program using the command: > > @dirs = Dir.glob(''*'') > > Then they suggest writing the code to display the directory > contents but don''t say how. So I wrote a file called app/views/say/ > dirlist.rb which has the following code: > > <html> > <head> > <title>Directory Listing</title> > </head> > <body> > <h1>Directory:</h1> > <p> > <%= @dirs %> > </p> > </body> > </html> > > The problem is that while all the file and directory names are > displayed, they are also all "run together". What would be the > easiest and most logical way to format the output so that the > filenames are separated by ", "? > > > > Get your own web address for just $1.99/1st yr. We''ll help. Yahoo! > Small Business. > --~--~---------~--~----~------------~-------~--~----~ > 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 > -~----------~----~----~----~------~----~------~--~--- >
> <%= @dirs %> > > What would be the easiest and most logical way to format > the output so that the filenames are separated by ", "?<%= @dirs.join '','' %> or one per line: <%= @dirs.join ''<br />'' %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you, Peter. I was wondering if maybe you can think of another approach that involves some sort of "iteration process" so that the final array element can be treated differently. I was reading the manual regarding arrays and there is an example that goes like this: Given an array called a, a.each { |name| puts "Got #{name}" } Any further insights? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you Curtis...very, very much!!! I have saved both ways of doing this (yours and Peter''s) in my example file with comments in the HTML section. I''m sure there are dozens of other ways to do the same thing...but I like your first suggestion best of all. It shows me that you have significant Ruby experience and practical experience in helping other Ruby students. Many thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---