Refractor Factory 4/4: clarifications


#1

Okay, so I know that this whole lesson is very buggy but I did decide to continue and research any new terms I did not understand and also try to understand why the code ran the way it did and why it was done the way it was done BUT I do want to make sure that I have the following lines understood:18%20PM

Just to clarify, prime.next and Prime.new are both OBSOLETE and no longer used in Ruby, which is why the lesson is being so buggy.
Right?

The next thing is trying to make sure I completely understand what is going on with
require ‘prime’
and
Prime.first(n)

require ‘prime’:
This is receiving a module called Prime and giving us access its algorithm, which only picks prime numbers. We are able to call this module as many times as we want since ‘require’ receives an object and makes it so it doesn’t have to keep doing it.
Can ‘require’ be simplified down to this?: once in, always in until the program stops running.

Prime.first(n):
In combo with ‘Prime’, the method ‘.first()’ just displays the first (n) elements of the ‘Prime’ array.

So overall, these are what I’m trying to get clarified.
I’m just trying to make the best of a messy situation so I hope I, somewhat, got it down lol


#2

Once in memory, there is no limit to how many times the Prime class is instantiated. The module is present until the session is ended.

For convenience, each instance method of Prime .instance can be accessed as a class method of Prime .
https://ruby-doc.org/stdlib-2.3.0/libdoc/prime/rdoc/Prime.html


Addendum

Prime is not a stored array. It is computed with each new instantantiation. Given that there are infinitely many primes, it follows we would favor the computational approach when handling queries. We are not polling a reference.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.