This is not possible. I can't find the thread right now, but matz has explicitly said that this is by design. The problem is that the default value is an arbitrary expression, and since everything in Ruby is an expression, it can be anything.
For example, what about this:
def foo(bar = if rand < 0.5 then Time.now else rand end)
What would your proposed method return here?
Basically, you have two choices:
- Evaluate the default value expression. This means you will get some value, but that doesn't tell you much about what the real expression is.
- Don't evaluate the default value expression, by packaging it up in a
Proc
. But there's no way to get the expression out of a Proc
again.
So, either way, you don't actually get any useful information.