LoginSignup
3
0

More than 5 years have passed since last update.

Ruby でメソッドの引数の値を確認する

Last updated at Posted at 2017-12-24

思いついたので書いてみました。

method(__method__).parameters.map { |t, v| [v, eval(v.to_s)] }.to_h

使い方

def hoge(a = 3, b = 'hello', *test)
  p method(__method__).parameters.map { |t, v| [v, eval(v.to_s)] }.to_h
end

hoge #=> {:a=>3, :b=>"hello", :test=>[]}
3
0
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
3
0