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

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0