2

Suppose I have this method:

def person(name: "calvin")
  ...
end

I want to find the default value for param name. How would I do that?

Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
Vlad the Impala
  • 15,572
  • 16
  • 81
  • 124

2 Answers2

3

There is no list of parameter defaults, a default value is code that is executed.

def foo(t=Time.now)
  p t
end

foo  #2015-04-20 19:43:54 +0200
sleep 1
foo  #2015-04-20 19:43:55 +0200
steenslag
  • 79,051
  • 16
  • 138
  • 171
  • Good answer. Here's another simple example, where the default value depends on the number of times the method's been called: `@b = 0; def a(t=@b) @b += 1 end`. – Cary Swoveland Apr 20 '15 at 18:36
0

Not sure whether this will help, but person.send(:local_variables) might be a good starting point.

fylooi
  • 3,840
  • 14
  • 24