Too much refactoring?


I've been working through the ruby classes, all very fine stuff :slightly_smiling:

I think this example (taken directly from the course) is taking the refactoring too far (hint: I'm looking at the two "n must be ... " lines)

require 'prime'

def first_n_primes(n)
# Check for correct input!
"n must be an integer" unless n.is_a? Integer
"n must be greater than 0" if n <= 0

# The Ruby 1.9 Prime class makes the array automatically!
prime = Prime.instance
prime.first n

when called thus:
the code just hangs (or presumably tries to find the first -10 primes :wink:.

When I add back the "return" statements before "n must be ... " then it works as expected.


That's right, those "return" statements are needed.