Vladimir Tsukanov
Vladimir Tsukanov

Reputation: 4459

Ruby - method parameters

My method:

def my_method=(attributes, some_option = true, another_option = true)
  puts hello
end

When i try to call this, i get such error:

my_method=({:one => 'one', :two => 'two'}, 1, 1)
#you_code.rb:4: syntax error, unexpected ',', expecting ')'
#my_method=({:one => 'one', :two => 'two'}, 1, 1)
                                      ^  

What's the problem?

Upvotes: 2

Views: 215

Answers (2)

ShiningRay
ShiningRay

Reputation: 1008

Method with suffix punctuation = can have only one argument.

Otherwise, you must use send to invoke with multiple parameters.

send :'my_method=', {:a => 1}, 1, 1

Upvotes: 4

leonardoborges
leonardoborges

Reputation: 5629

Don't use parenthesis when invoking a method using the = syntactic sugar.

Invoke it like this:

mymethod= {:one => 'one', :two => 'two'}, 1, 1

Upvotes: 0

Related Questions