From: Adam Prescott Date: 2010-09-07T03:58:49+09:00 Subject: Re: A better idiomatic way of doing this?! On Mon, Sep 6, 2010 at 6:23 PM, Brian Candler wrote: > > On Tue, Sep 07, 2010 at 01:59:53AM +0900, Tim Romberg wrote: > > @Brian: Thanks for your feedback. I am aware that I'm not practicing > > "good" Ruby yet, I hope with more time I will develop. The reason why > > included the module was because one of the musts with the assignment was > > to output a menu through a module. > > In your original code you only had class methods, so you could have defined > them directly on a module instead: > > module Menu >  def self.whatever >    puts "Hello" >  end > end > Menu.whatever > > This is because a class *is* a module, just with the extra abilities of > creating instances and subclassing, which you weren't using. > > > When I want to create the other menus > > as you stated with the main_menu example can I just continue creating > > the menu objects equally?! For example: > > m = Menu.new ["Checkin","Checkout","Lists","Economy","Exit"] > > m.main_menu > > m = Menu.new ["list current guests","list all guests","back to main > > menu"] > >  m.lists_menu > > Sure; or store them in different variables (or constants) and then re-use > them as you like.  You might choose a more descriptive name for your method > which prints the menu and lets the user choose a selection. > > main_menu = Menu.new ["Checkin","Checkout","Lists","Economy","Exit"] > lists_menu = Menu.new ["list current guests","list all guests","back to main > menu"] > main_menu.choose > lists_menu.choose > > Regards, > > Brian. > I'd also like to add that this would be good for simplicity: class Menu def self.[](*args) self.new(*args) end end to allow you to say main_menu = Menu["Checkin","Checkout","Lists","Economy","Exit"]