What is wrong with this code?

require 'mathn' prime_number = Prime.new 

Displays error:

 `<top (required)>': private method `new' called for Prime:Class (NoMethodError) from -e:1:in `load' from -e:1:in `<main>' 

I want him to write out prime numbers less than 90, but without this line it still doesn’t work

 prime_number.each {|prime| print prime," ";break unless prime<90} 

    1 answer 1

    Ruby is not lying. The Prime class does not have a new method .

    new ()

    obsolete Use Prime::instance or class methods of Prime .

    More precisely, there is, but hidden, actually prohibited to use. Yes, and not needed.

    Your code is most likely from those times when Ruby 1.8 was still relevant. But not in 2017!

    Most likely, instead of prime_number you need Prime itself, as a last resort Prime.instance . Specifically, the code snippet you give works fine with Prime :

     Prime.each {|prime| print prime," ";break unless prime<90} 
    • Fine! And in truth, everything works! Thank! - Igor