title: Named parameters in Ruby 2
body: <p>I don't understand completely how named parameters in Ruby 2.0 work. </p>
  
  <pre><code>def test(var1, var2, var3)
    puts "#{var1} #{var2} #{var3}"
  end
  
  test(var3:"var3-new", var1: 1111, var2: 2222) #wrong number of arguments (1 for 3) (ArgumentError)
  </code></pre>
  
  <p>it's treated like a hash. And it's very funny because to use named parameters in Ruby 2.0 I <strong>must</strong> set default values for them:</p>
  
  <pre><code>def test(var1: "var1", var2: "var2", var3: "var3")
    puts "#{var1} #{var2} #{var3}"
  end
  
  test(var3:"var3-new", var1: 1111, var2: 2222) # ok =&gt; 1111 2222 var3-new
  </code></pre>
  
  <p>which very similar to the behaviour which Ruby had before with default parameters' values:</p>
  
  <pre><code>def test(var1="var1", var2="var2", var3="var3")
    puts "#{var1} #{var2} #{var3}"
  end
  
  test(var3:"var3-new", var1: 1111, var2: 2222) # ok but ... {:var3=&gt;"var3-new", :var1=&gt;1111, :var2=&gt;2222} var2 var3
  </code></pre>
  
  <p>I know why is that happening and almost how it works. </p>
  
  <p>But I'm just curious, <strong>must</strong> I use default values for parameters if I use named parameters? </p>
  
  <p>And, can anybody tell me what's the difference between these two then?</p>
  
  <pre><code>def test1(var1="default value123")
    #.......
  end
  
  def test1(var1:"default value123")
    #.......
  end
  </code></pre>