Skip to content
Tags

, ,

Passing parameters in an array

April 7, 2011
def test a, b, c

puts a

puts b

puts c

end

=> nil

ruby-1.9.2-p0 :045 > arr = [1, 2, 3]

=> [1, 2, 3]

ruby-1.9.2-p0 :046 > test arr

ArgumentError: wrong number of arguments (1 for 3)

from <main>:0:in `test'

from (irb):46

from /Users/gaganawhad/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start'

from /Users/gaganawhad/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start'

from /Users/gaganawhad/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>'

from script/rails:6:in `require'

from script/rails:6:in `<main>'

ruby-1.9.2-p0 :047 > test *arr

1

2

3

=> nil
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: