Forum: Ruby on Rails One Liner Please

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2073c7e0e7d2311727b680a887a375be?d=identicon&s=25 leonleslie (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
526d60de6472502bb570a9df2842b33b?d=identicon&s=25 nicksieger (Guest)
on 2005-11-12 12:49
(Received via mailing list)
On 11/9/05, Leon Leslie <leonleslie@gmail.com> 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
2073c7e0e7d2311727b680a887a375be?d=identicon&s=25 leonleslie (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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 Sieger <nicksieger@gmail.com> wrote:
> >
> > outstanding
>  /Nick
>
>


--
First they laugh at you, then they ignore you, then they fight you.
Then you win.
-- Mahatma Karamchand Gandhi
526d60de6472502bb570a9df2842b33b?d=identicon&s=25 nicksieger (Guest)
on 2005-11-12 12:49
(Received via mailing list)
On 11/10/05, Leon Leslie <leonleslie@gmail.com> 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
This topic is locked and can not be replied to.