From: Jano Svitok Date: 2008-05-02T16:07:44+09:00 Subject: Re: Need help converting PHP to Ruby / eRuby On Fri, May 2, 2008 at 4:11 AM, James Nykiel wrote: > Thanks for the help with this, do you know if or how I can combine the > following: > > ## menu.rhtml > > <% fname = File.basename ENV['SCRIPT_FILENAME'] > > if fname == 'index.rhtml' %> > Home   ::   > <% else %> > Home   ::   > <% end %> > > <% fname = File.basename ENV['SCRIPT_FILENAME'] > if fname == 'contact.rhtml' %> > Contact   ::   > <% else %> > Contact > >   ::   > <% end %> <% def menu_item(current_filename, page_filename, page_title) if current_filename == page_filename page_title else "#{page_title}" end end fname = File.basename ENV['SCRIPT_FILENAME'] %> <%= menu_item(fname, "index.rhtml", "Home") %>   ::   <%= menu_item(fname, "contact.rhtml", "Contact" %>   ::   You can continue with storing the menu in an array, i.e. <% def make_menu(menu, separator) fname = File.basename ENV['SCRIPT_FILENAME'] menu.map {|page_file, page_title| menu_item(fname, page_file, page_title)}.join(separator) end MENU = [ ['index.rhtml, 'Home'], ['contact.rhtml', 'Contact'] ] %> <%= make_menu(MENU, "   ::   ") %>