Vlad the Impala
Vlad the Impala

Reputation: 15872

How can I get the default values for named arguments for a method?

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?

Upvotes: 2

Views: 108

Answers (2)

steenslag
steenslag

Reputation: 80065

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

Upvotes: 3

fylooi
fylooi

Reputation: 3870

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

Upvotes: 0

Related Questions