From: "duckinator (Nick Markwell)" Date: 2012-10-28T11:25:41+09:00 Subject: [ruby-core:48511] [ruby-trunk - Feature #6727] Add Array#rest (with implementation) Issue #6727 has been updated by duckinator (Nick Markwell). Sorry that I forgot to check this again before. I've done a bit of thinking and poking around since I ran across this again today. Regarding [].rest == nil vs [].rest == []: [] is treated as a truthy value, so there if rest returns that, then there is a significant difference when #rest is used in place of [1..-1] -- you'd have to check if the original list is empty yourself, so *if this gets added* it is of no use unless it returns nil under those circumstances. Regarding examples of it used in practice: Just from code I happened to already have on my system, there is 501 instances of [1..-1] in Ruby code. https://gist.github.com/3967189 Out of what I have on my system it is, surprisingly, used mostly in relation to Ruby interpreters: 217 instances in MRI's git repo, 162 instances in Rubinius' git repo, 95 instances in JRuby's git repo. Aside from that, on my system the usages are mostly small: 4 uses by Bundler, 11 instances by what I believe are WebKit's build scripts, 4 times by cinch, and 8 times in various other things. Other thoughts: Perhaps Array#rest(n=1) being equivalent to Array#[n..-1], including returning nil for [].rest, would be a better approach? That way it isn't strict to the point of being nearly useless, but is still short and to the point. ---------------------------------------- Feature #6727: Add Array#rest (with implementation) https://bugs.ruby-lang.org/issues/6727#change-31845 Author: duckinator (Nick Markwell) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: next minor =begin I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous. Branch on github: (()) Patch: (()) Diff: (()) =end -- http://bugs.ruby-lang.org/