3/7 Omit Words


#1

The following code is what I have refactored for this exercise. I get a syntax error. What is wrong with my unless and/or if statements here?

$VERBOSE = nil # We'll explain this at the end of the lesson.
require 'prime' # This is a module. We'll cover these soon!

def first_n_primes(n)

puts "n must be an integer." unless Integer
end

puts "n must be greater than 0." if n <= 0
end

prime_array ||= []

prime = Prime.new
for num in (1..n)
prime_array.push(prime.next)
end
return prime_array
end

first_n_primes(10)


#2

You don't need the end keyword when your control structure is on one line.

Also, don't you think that there's a problem with:

unless Integer

#3

i didn't understand it yet... can someone send me his/her code?


#4

Try this:

puts "n must be an integer." unless Integer
puts "n must be greater than 0." if n <= 0


#5

It also works with return, should we use puts or return for this, since the original code used return?

example:

return "n must be an integer." unless n.is_a? Integer

return "n must be greater than 0." if n <= 0

#6

as well this works... implicit return instead of puts or using return

"n must be an integer." unless n.is_a? Integer
"n must be greater than 0." if n <= 0