Bug #9722

Failure with multiple keyword arguments

Added by Thomas Cioppettini over 1 year ago. Updated over 1 year ago.

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

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 Updated by Matthew Kerwin over 1 year ago

Is this the same as #9669 ?

#2 Updated by Nobuyoshi Nakada over 1 year ago

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

#3 Updated by Nobuyoshi Nakada over 1 year 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 Updated by Tomoyuki Chikanaga over 1 year 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