Skip to content

Instantly share code, notes, and snippets.

@bagwanpankaj
Created February 7, 2011 18:28
Show Gist options
  • Save bagwanpankaj/814904 to your computer and use it in GitHub Desktop.
Save bagwanpankaj/814904 to your computer and use it in GitHub Desktop.
Ruby 1.9 Defining Spalt arguments
#tested with ruby 1.9.2
#first argument as spalt argument.
def test_splat(*a, b)
"a:#{a},b:#{b}"
end
#So in this last argument would be assigned to b and all others would be to a
test(1,2,3,4,5,6)
#=> "a:[1, 2, 3, 4, 5],b:6
#tested with ruby 1.9.2
#splat arg in middle of arguments.
def test_splat_middle(a, *b, c)
"a:#{a},b:#{b},c:#{c}"
end
#So in this first argument would be assigned to a, last to c and all others would be to b
test_splat_middle(1,2,3,4,5,6)
#=> "#a:1,b:[2, 3, 4, 5],c:6"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment