jmmastey/level_up_exercises — pull request #214 by paulh16 (2014-11-04 14:57:43+00:00)
Title: Robot name pgh

My main changes in this iteration were the following:

1. Delete the @@registry class variable declaration on Line 6 of the original. I don't believe it is needed since it is set in the initialize method.

2. In line 6 of the new file, I extracted the RegEx from the Raise. I also added a ^ to the beginning and a $ to the end to strictly enforce 2 alpha characters followed by 3 numeric characters in the name. Prior to this change, the RegEx was matching other expressions, such as 3 alpha - 3 numeric.

3. I extracted 4 short methods form lines 12-23 of the original. My goal was to create short, focused methods with a single purpose:
* assign_name: creates the name that is assigned to the @name instance variable.
* generate_new_name: calls the lambdas to generate a random name; note that I simplified the calls to the lambdas using multiplication.
* assert_valid_name: raises errors under two conditions: the name is not valid; the name already exists. I also separated the two error conditions into two separate expressions for clarity and created new error messages, specific to the error raised.
* add_name_to_registry: appends the new name to the @@registry class variable.

4. I extracted two methods, character and number, that define, and then call, the lambdas. This DRYs out the calls in the original version. I also made them private. I'm not sure if this is essential, but I felt they should only be called from within this class.