One Liner Please

Hi Railers,

I have the following code which attempts to find missing years in a
list of active records.

It creates a range of years for which filing documents are required.
Then deletes all the years for which there are documents
returning a list of years for which no documents where found.

I am newbie to ruby, rails and blocks. Can someone help me write this
more effectively?

def outstanding_annual_return_years
outstanding = []
result = formation_date.strftime("%Y").to_i
result.upto(Time.now.strftime("%Y").to_i) {|y| outstanding << y}
filed_documents.each {|d|
outstanding.delete d.filing_date.strftime("%Y").to_i
}
outstanding
end

Thanks

On 11/9/05, Leon L. [email protected] wrote:

I am newbie to ruby, rails and blocks. Can someone help me write this
end
I’ll bite. Not tested - just written into the email:

| def outstanding_annual_return_years
| [formation_date.year…Date.new.year] - filed_documents.map{|doc|
doc.filing_date.year }
| end

Let me know if it works :slight_smile:
/Nick

Hi /Nick

It does not work.
Two observerations
[formation_date.year…Date.new.year] Returns a range instead of an
array
Date.new.year does not return the current year

On 11/9/05, Nick S. [email protected] wrote:

outstanding
/Nick


First they laugh at you, then they ignore you, then they fight you.
Then you win.
– Mahatma Karamchand Gandhi

On 11/10/05, Leon L. [email protected] wrote:

Hi /Nick

It does not work.
Two observerations
[formation_date.year…Date.new.year] Returns a range instead of an array
Date.new.year does not return the current year

My mistake, that’s what I get for not consulting the doco. Should be
this:

| def outstanding_annual_return_years
| (formation_date.year…Date.today.year).to_a - filed_documents.map{|doc|
doc.filing_date.year }
| end