From: nobu@... Date: 2014-03-05T06:56:57+00:00 Subject: [ruby-core:61302] [ruby-trunk - Bug #9593] [Closed] Keyword arguments default argument assignment behaviour not consistent with optional argument Issue #9593 has been updated by Nobuyoshi Nakada. Status changed from Open to Closed % Done changed from 0 to 100 Applied in changeset r45272. ---------- parse.y: optional arguments in rhs * parse.y (f_arg_asgn): define optional arguments as argument variables in the rhs default expressions. [ruby-core:61299] [Bug #9593] ---------------------------------------- Bug #9593: Keyword arguments default argument assignment behaviour not consistent with optional argument https://bugs.ruby-lang.org/issues/9593#change-45633 * Author: Jack Chen * Status: Closed * Priority: Normal * Assignee: Yukihiro Matsumoto * Category: syntax * Target version: current: 2.2.0 * ruby -v: 2.1.1 * Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- Given the following code: def var 100 end def foo(var: var + 1) puts "var: #{var.inspect}" end def bar(var = var + 1) puts "var: #{var.inspect}" end foo(var: 1) foo rescue p $! bar(1) bar Ruby 2.0.0: var: 1 var: 101 var: 1 var: 101 Ruby 2.1.1: var: 1 # var: 1 var: 101 What appears to be happening is that since 2.1.1, the keyword argument defines `var` as a variable before evaluating the default argument. Personally, I prefer 2.0.0 behaviour, but the way 2.1.1 handles default arguments in non keyword arguments is inconsistent. -- http://bugs.ruby-lang.org/