Help Ruby Programming - judge whether the prime

Below is my code, but the thought feeling yes, please master to help me have a look, what happened.
class Apple
def initialize data
@data=data
end
def info1
i=2
while i<@data
puts @data%i
if @data%i==0
break
i+=1
end
end
end
def info2
if (@data%i)==0
puts data+"Is not a prime"
else
puts data+"Is a prime number"
end
end
end
r=Apple.new(51)
r.info1
r.info2

Started by Scott at November 14, 2016 - 1:27 PM

The problem has been resolved··
I halo, actually very simple
I want to complex
a=25
i=2
b=1
while i<=Math.sqrt(a) do
b*=(a%i)
i+=1
end
if b==0 then
puts a.to_s+"Is not a prime"
else
puts a.to_s+"Is a prime number"
end

We have more simple way to do

Posted by Scott at November 17, 2016 - 1:29 PM

A standard library prime 1.9, load the library, will increase prime in integer? Methods: examples are as follows:
require 'prime'

60.prime?
1.prime?

More functions can refer to this document library.

Posted by Carr at November 26, 2016 - 1:58 PM

On the top floor, the most simple and calls the library rules.

Posted by Lou at December 01, 2016 - 2:25 PM

2.upto(n) do |x|
2.upto(n-1) do |i|
If a x%i==0 is not a prime number
end
end

Posted by Cassie at December 07, 2016 - 3:10 PM

The landlord that grammar is C.

Posted by Brenda at December 13, 2016 - 3:32 PM

The top 2 floors of the building

Posted by Beatrice at December 20, 2016 - 4:27 PM

class Fixnum
  def pri?
    (2..self-1).each{|x|
      return 'not prime' if self % x == 0
    }
    'prime'
  end
end
 
puts gets.to_i.pri?


The corresponding explanation here

Posted by Nigel at December 21, 2016 - 5:20 PM