Project

General

Profile

Bug #9722

Failure with multiple keyword arguments

Added by Thomas Cioppettini over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
ruby -v:
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
[ruby-core:61940]

Description

I am running ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
Given the following person class:

class Person
  attr_reader :name, :age

  def initialize name:, age:
    @name = name
    @age    = age
  end
end

There are a few cases of unexpected behavior when you instantiate a Person class given the above code.

Failure 1:

person = Person.new(name: "Tom", age: 24)
person.name # expect "Tom"
=> nil
person.age # expect 24
=> 24

Failure 2:

person = Person.new(name: "Tom") # expect ArgumentError missing keyword age
person.name 
=> "Tom"
person.age 
=> "Tom"

If I were to just give an age keyword argument instantiation would fail as expected.


Related issues

Duplicates Ruby trunk - Bug #9669: Inconsistent SyntaxError in Ruby 2.1 mandatory keyword arguments definition without parentheses. Closed 03/25/2014

History

#1 [ruby-core:61941] Updated by Matthew Kerwin over 2 years ago

Is this the same as #9669 ?

#2 [ruby-core:61951] Updated by Nobuyoshi Nakada over 2 years ago

  • Duplicates Bug #9669: Inconsistent SyntaxError in Ruby 2.1 mandatory keyword arguments definition without parentheses. added

#3 [ruby-core:61953] Updated by Nobuyoshi Nakada over 2 years ago

  • Description updated (diff)
  • Status changed from Open to Closed
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: DONTNEED, 2.1: REQUIRED

#4 [ruby-core:62663] Updated by Tomoyuki Chikanaga over 2 years ago

  • Backport changed from 2.0.0: DONTNEED, 2.1: REQUIRED to 2.0.0: DONTNEED, 2.1: DONE

r45405 and r45408 were backported into ruby_2_1 branch at r46005.

Also available in: Atom PDF