lukexorz/Chemistry — pull request #2 by MiltonStanley (2013-05-01 15:33:28+00:00)
Title: Update periodicTable.rb

Things to do:
* Look over some Ruby style guides. This is a very Java way of doing this.
* Think about how you're gonna reference each element in the table - Atomic #? Weight? Abbreviation? Name? If it's atomic #, then Array is fine, but it's mainly gonna be something else, use a Hash object for the table, with the key being what you'll reference with, and the value being an Element object.
* Remove .make from all the elements (I did some, but got bored). Just use the parameters passed into new, which is the same method as initialize() in the class definition.
* The ever popular DRY - Don't Repeat Yourself. One of the strengths of Ruby is iteration. For example, you could create Arrays that hold the chemical symbol, name, abbreviation, weight, etc. Then iterate over a range (Class::Range), a Ruby feature: (1..109). Iterate over each piece of data, use that data to reference an index in each of the Arrays you've created, then pass all that into the Element.new(...) function, and finally append that new element to the Table object. This will also remove the problem above of having to make a fake object for index 0. This is what I did above in the comments.
* If you DO use an Array, use nil for the first object. As always, I think it's better to crash than to silently accept wrong data.
* USE TEST DRIVEN DEVELOPMENT! A quick test like: def test_not_nil; table.each { |element| assert_not_nil element }; end would have caught that the elements weren't getting into the array.
* MINSWAN - Matz is nice so we are nice. Ruby is fun!