From: Guest Date: 2006-04-21T06:54:11+09:00 Subject: Re: Optional Message Parameters? Nathan Olberding wrote: > (Warning: Newbie Altert!) > > How do I write a method with optional params? I would think that this: > > def do_this(opt1="", opt2="") > puts opt2 > end > do_this(opt2="This") > > > Would result in "This" being displayed. Instead, "This" becomes the > value of opt1. I'd like to set opt1 and opt2 to default to "". How do I > do that? Use a hash: def do_this( args ) puts args[:opt2] end do_this :opt2=>"This" #=> This What you're doing now is assigning to opt2 then passing it: do_this(opt2="This") puts opt2 #=> "This" -- Posted via http://www.ruby-forum.com/.