Return with Splat in Ruby 1.9
This looks like a bug to me…(‘cept I’m sure it’s not)
$ cat splats.rb
def splat1
rv = [nil]
return *rv
end
def splat2
rv = [nil,nil]
return *rv
end
foo = splat1
bar, baz = splat2
puts foo.inspect
puts bar.inspect
puts baz.inspect
$ ruby -v
ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin9.6.0]
$ ruby splats.rb
nil
nil
nil
$ ruby -v
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9.7.0]
$ ruby splats.rb
[nil]
nil
nil
(Notice the difference when returning the splatted array [nil].)
EDIT: I forgot to check the ‘question’ box on Tumblr, but if you know what’s going on here, please get it touch.