LoginSignup
14
13

More than 5 years have passed since last update.

Ruby2.1.0からデフォルト値なしのキーワード引数が使えると聞いて

Last updated at Posted at 2014-06-22

Ruby 2.1.0リリース!注目の新機能を見てみましょう | TechRacho に書いてある

def hello(name: )
puts name
end

hello("taro")
# => taro
# 実際はこうなる => ArgumentError: missing keyword: name

という例は動かないみたいだ. しばらく悩んでしまった. 「デフォルト値なし」というよりも「必須指定ができるようになった」と言う方がしっくり来た.

RUBY_VERSION
#=> "2.1.0"

def hoge(a: )
  p a
end

hoge(a: 'aaa')
#=> "aaa"

hoge('aaa')
#=> ArgumentError: missing keyword: a

hoge
#=> ArgumentError: missing keyword: a
14
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13