From: Greg Millam Date: 2002-12-18T08:24:50+09:00 Subject: Re: named parameters On Wed, 18 Dec 2002, Daniel Carrera wrote: > Is there a way to write a function with named parameters? > Something like: > > Header { 'title' => "Somr Title"} > > Is there any other way? Thi sis the way given in the Pickaxe. http://ruby-central.com/book/tut_methods.html > How about default values for parameters? How can I do those? Shown in the same page I gave above. def foo(bar,baz="Baz") puts "Foo, #{bar}, #{baz]" end foo("hello") -- Foo, hello, Baz --- As for combining the two - having default values for hash arguments passed, that's quite a bit tricker. only way I can think of is def foo(params) params["baz"] = "Baz" unless params["baz"] params["bar"] = "beer" unless params["bar"] ... end The problem with this method is, if a programmer wants to pass 'nil' or 'false' or any non-true value as an argument, the default values would overwrite that. Hope that helps, Greg > Thanks a lot, > Daniel Carrera > Graduate Teaching Assistant. Math Dept. > University of Maryland. (301) 405-5137 > > -- Greg Millam walker at deafcode.com