Can't call my method? wrong number of arguments

hey guys, i’m new to ruby but i can’t figure out what is wrong with my
code. i get the error “rb:311:in `test’: wrong number of arguments (0
for 1) (ArgumentError)” for this:

def test date
return_test = nil
return_date = nil
self.results.each do |result1|
if result1.parameter.id == ‘T’
if result.date < date
return_test = result.value
return_date = result.date
if !return_date.nil? && result.date > return_date
return_date = result.date
return_test = result.value
end
end
end
end
return return_test
end

and i try to call it here wich gives me the error:

dig_k = 0
patient.labresults.each do |m|
unless patient.test.nil?
if patient.test.date(m.startdat)<2.8
patient.medications.each do |m2|
if m.medi.atc =~ /^C01AA05/
dig_k+=1
end
end
end
end

what causes the error?

thank you very much!
cheers

Tja Tja wrote in post #1182322:

def test date
return_test = nil
return_date = nil
self.results.each do |result1|
if result1.parameter.id == ‘T’
if result.date < date
return_test = result.value
return_date = result.date
if !return_date.nil? && result.date > return_date
return_date = result.date
return_test = result.value
end
end
end
end
return return_test
end

in each loop, yo use result1 and result …
Something like that should do the job :

class …
def test(date)
best=result.select {|r|
r.parameter.id == ‘T’ && r.date < date
}.max_by {|r| r.date}
best ? best.value : nil
end
end

dig_k = 0
patient.labresults.each do |m|
unless patient.test.nil?
if patient.test.date(m.startdat)<2.8
patient.medications.each do |m2|
if m.medi.atc =~ /^C01AA05/
dig_k+=1
end
end
end
end

you use m2 and m in second each loop …

dig_k = patient.labresults.select { |r|
patient.test && patient.test.date(r.startdat)<2.8
}.each_with_object(0) { |r,sum|
sum+= patient.medications.each_with_object(0) {|m2,sum2|
sum2+=1 if m2.medi.atc =~ /^C01AA05/
}
}