Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Array Ranges

(2011..1995).to_a 

returns an array

(Time.now.year.to_i..1995).to_a

doesn't. Why?

like image 936
Neil Middleton Avatar asked Feb 09 '11 13:02

Neil Middleton


2 Answers

try

> 2011.downto(1995).to_a
=> [2011, 2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003, 2002, 2001, 2000, 1999, 1998, 1997, 1996, 1995]
like image 189
kurumi Avatar answered Oct 15 '22 07:10

kurumi


You can use this

(Time.now.year.to_i).downto(1995).to_a

like image 29
Mahesh Avatar answered Oct 15 '22 06:10

Mahesh