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
=> nil

Labels: , ,

» Post a Comment

Who we are:
The Pasadena Ruby Brigade is a group of programmers who are interested in Ruby. We enjoy sharing our ideas and code with anyone who is interested in this wonderful programming language.

Who can join:
Anyone! Just head over to our mailing list and drop us an email.

What we do:
We recently started a project over at RubyForge. This project is a group of programs written and maintained by our members that we thought could be beneficial to the whole community.



Recent Posts