From: James Edward Gray II Date: 2006-09-21T23:06:15+09:00 Subject: Re: Request for code review of beginning project On Sep 21, 2006, at 2:55 AM, Ben Schaffhausen wrote: > Hello, Hello and welcome to Ruby. > To start I am making a few classes to model the buildings and delivery > or materials to and from other buildings. Currently the program is > ~250 > lines long and seems to work within my intentions thus far. "seems to work" is a good sign that you might enjoy learning a little about unit testing. You could build tests to to ensure that it is indeed working as you expect and give you peace of mind as the code grows. > Still I can't help but feel that the code is messy or that I'm doing > things the hard way/non-ruby-way. I really didn't see any big red flags in the code. Mostly you are assigning to or making minor adjustments to variables. There's not a lot for us to improve on for something like that. Some general tips: * Drop the parens around if( ..) lines. Ruby doesn't need them. * Try to use indices as little as possible. They are generally un- Rubyish. Here's an example targeting your queue: >> # with indices... ?> @q = [ ["Beads", "Denver", "Oklahoma City"], ?> ["Keyboards", "New Haven", "Chicago"] ] => [["Beads", "Denver", "Oklahoma City"], ["Keyboards", "New Haven", "Chicago"]] >> # show what is going to where ?> @q.each { |item| puts "#{item[0]} to #{item[2]}" } Beads to Oklahoma City Keyboards to Chicago => [["Beads", "Denver", "Oklahoma City"], ["Keyboards", "New Haven", "Chicago"]] >> # without indices... ?> Shippment = Struct.new(:product, :origin, :destination) => Shippment >> @q = [ Shippment.new("Beads", "Denver", "Oklahoma City"), ?> Shippment.new("Keyboards", "New Haven", "Chicago") ] => [#, #] >> # show what is going to where ?> @q.each { |ship| puts "#{ship.product} to #{ship.destination}" } Beads to Oklahoma City Keyboards to Chicago => [#, #] Hope that helps. James Edward Gray II