Using Parameters as Default Parameters
Tuesday, March 06, 2007 by Nate Murray.
I noticed something interesting about arguments in parameters today. You can actually use default parameters in data structures in other default parameters. For instance:
[nathan@nate ~]$ irb >> def foo(arg1, arg2 = [arg1]) >> puts arg1.inspect >> puts arg2.inspect >> end => nil >> foo 3 3 [3] => nil
Labels: interesting, ruby, snippets