Ruby does not pass keyword arguments. (Not yet, in any case, this is one of the things that could turn it into Ruby 2.0. However, there are no guarantees, and work on Ruby 2.0 has not yet begun, so it is not reported when or even if we see keywords in Ruby .)
What really happens is: you pass the expression arg2 = 4 as the only argument in the argument list. Ruby is a rigorous pass-by-value language, which means that all arguments are fully evaluated before they are passed to the method. In this case, arg2 = 4 is an assignment expression (in Ruby, everything is an expression (i.e., All returns a value), there are no instructions). You assign the current Fixnum Fixnum value 4 value of the local variable arg2 . Assignment expressions always return the value of their right-hand side, in this case 4 .
So, you pass the value 4 as the only argument to your method, which means that it is bound to the first required parameter, if there is one (in this case it is not), otherwise the first optional parameter (in this case arg1 ).
The usual way to deal with such situations is to use Hash , namely:
some_method({:arg2 => 4})
Since this pattern is used so often, there is special syntactic support: if the last argument to the method is Hash , you can leave curly braces:
some_method(:arg2 => 4)
There is another syntactic form of convenience in Ruby 1.9: since Hash es are often used with Symbol keys, there is an alternative Hash syntax for this:
some_method({arg2: 4})
Combine them both, and you almost have keyword arguments:
some_method(arg2: 4)
(In fact, both of these shortcuts have been specifically added to provide an easy way to get to possible future versions of Ruby with keyword arguments.)
MacRuby actually supports Smalltalk-style multiple message selectors for interacting with Objective-C. Note, however, that Smalltalk multipoint selector types are not keyword arguments; they behave differently. In addition, this extension applies to MacRuby, but does not apply to the Ruby specification, but is not ported to MRI, YARV, JRuby, XRuby, IronRuby, MagLev, Rubinius, tinyrb, RubyGoLightly, BlueRuby, SmallRuby, or any other Ruby implementation.