I am new to Ruby and don't know how to access data members within a function (syntax-wise). Here is my question. I have a function that will put values into an array of numbers, from a user given range, that are prime. The function looks like so:
#Search for primes within a range
def find_primes(starting, ending)
#Make an empty array
a = []
for x in starting..ending
if is_prime(x)
a << x #Store results in array
end
end
yield
end
The catch is that I must use the yield keyword to call another function to get the data from array 'a'. For example, I need to print out consecutive prime numbers, that are stored in 'a', and I have this code to do this (except I don't know how to get at the values of 'a' from the code below. This is called closure, I believe)
find_primes(0,50) do
i = 0
while i < a.size - 1
print "[#{a[i]} #{a[i+1]} "
end
end
This is all very new to me and I can't find a good source on how to do what I am tasked to do. Thank you in advance
Primealso.