class Lod
attr_accessor :lodnr
attr_accessor :lobnr
attr_accessor :stknr
def initialize(lodnr, lobnr, stknr)
@lodnr = lodnr
@lobnr = lobnr
@stknr = stknr.chomp
end
def to_s
"%8s, %5s, %3s" % [@lodnr, @lobnr, @stknr]
end
end
I have an array called sold
which contains these four arrays:
[10000, 150, 5]
[500, 10, 1]
[8000, 171, 3]
[45, 92, 4]
The four arrays are objects of a class, imported from at .txt file.
input = File.open("lodsedler.txt", "r")
input.each do |line|
l = line.split(',')
if l[0].to_i.between?(0, 99999) && l[1].to_i.between?(1, 180) && l[2].to_i.between?(1, 10)
sold << Lod.new(l[0], l[1], l[2])
else
next
end
end
I want to count the first value in each array, looking for a randomly selected number which is stored in first
.
The error I get is always something like this, whatever i try:
Undefined method xxx for #Lod:0x0000000022e2d48> (NoMethodError)
The problem is that i can't seem to acces the first value in all the arrays.