Hey all,
I have this:
def initialize
@a = []
end
def create_site!
puts "New Site"
50.times do |number|
site = @sites.sample
site_num = ensure_unique(site.site_num + random(001,999).to_s)
puts site_num.length
puts site_num.is_a?(String)
site = site! :site => site, :site_num => site_num
end
end
def ensure_unique(num)
@a << num
return num if [email protected]? num
end
The above raises an exception:
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.length
What is the best way to ensure unique random number being returned from
a method?
Thanks for response