# One Liner Please

**URL:** <https://www.ruby-forum.com/t/one-liner-please/93853>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/one-liner-please/93853 "2005-11-12T12:49:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonleslie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e99b99/32.png) [@leonleslie](https://www.ruby-forum.com/u/leonleslie)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/one-liner-please/93853/1 "2005-11-12T12:49:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![leonleslie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e99b99/32.png) [@leonleslie](https://www.ruby-forum.com/u/leonleslie)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/one-liner-please/93853/2 "2005-11-12T12:49:40Z")

</div>

On 11/9/05, Leon L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂  
/Nick

---

<div class="post-metadata">

**Author:** ![leonleslie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e99b99/32.png) [@leonleslie](https://www.ruby-forum.com/u/leonleslie)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/one-liner-please/93853/3 "2005-11-12T12:49:46Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > outstanding  
> > /Nick

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

---

<div class="post-metadata">

**Author:** ![leonleslie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e99b99/32.png) [@leonleslie](https://www.ruby-forum.com/u/leonleslie)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/one-liner-please/93853/4 "2005-11-12T12:49:47Z")

</div>

On 11/10/05, Leon L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
