DEV Community

Shuichi Tamayose
Shuichi Tamayose

Posted on

Check values of method arguments in Ruby

I try it.

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

Example

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

foo #=> {:a=>3, :b=>"hello", :test=>[]}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)