Project

General

Profile

Actions

Bug #9722

closed

Failure with multiple keyword arguments

Added by tomciopp (Thomas Cioppettini) over 10 years ago. Updated over 10 years ago.

Status:
Closed
Assignee:
-
Target version:
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 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #9669: Inconsistent SyntaxError in Ruby 2.1 mandatory keyword arguments definition without parentheses.Closed03/25/2014Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0