Ruby/Array/slice

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

slcie with range parameter

year = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009]
p year.slice(0..2) # => [2000, 2001, 2002]



slice with exclusive range parameter

year = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009]
 
p year.slice(0...2) # => [2000, 2001]



slice with one parameters

year = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009]
p year.slice(1) # => 2001



slice with two parameters

year = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009]
p year.slice(0,4) # => [2000, 2001, 2002, 2003]