title: How can I test if a value is a prime number in Ruby? Both the easy and the hard way?
body: <p>I am trying to create a program that will test whether a value is prime, but I don't know how. This is my code:</p>
  
  <pre><code>class DetermineIfPrime
  def initialize (nth_value)
  @nth_value = nth_value
  primetest
  end
  
  def primetest
    if Prime.prime?(@nth_value)
     puts ("#{@nth_value} is prime")
    else
     puts ("This is not a prime number.")
    end
  rescue Exception
  puts ("#{$!.class}")
  puts ("#{$!}")
   end
  end
  </code></pre>
  
  <p>And every time I run that it returns this.</p>
  
  <pre><code>NameError
  uninitialized constant DetermineIfPrime::Prime
  </code></pre>
  
  <p>I tried other ways to do the job, but I think this is the closest I can get.</p>
  
  <p>I also tried this:</p>
  
  <pre><code>class DetermineIfPrime
  def initialize (nth_value)
  @nth_value = nth_value
  primetest
  end
  
   def primetest
   for test_value in [2, 3, 5, 7, 9, 11, 13] do
    if (@nth_value % test_value) == 0
     puts ("#{@nth_value} is not divisible by #{test_value}")
    else
     puts ("This is not a prime number since this is divisible by #{test_value}")
    break
    end
   end
   end
  end
  </code></pre>
  
  <p>Or am I just doing something wrong?</p>