Actions
Bug #9722
closedFailure with multiple keyword arguments
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.
Updated by phluid61 (Matthew Kerwin) over 10 years ago
Is this the same as #9669 ?
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
- Is duplicate of Bug #9669: Inconsistent SyntaxError in Ruby 2.1 mandatory keyword arguments definition without parentheses. added
Updated by nobu (Nobuyoshi Nakada) over 10 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
Updated by nagachika (Tomoyuki Chikanaga) over 10 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.
Actions
Like0
Like0Like0Like0Like0