From: Damjan Rems Date: 2008-03-04T07:11:22+09:00 Subject: Re: Why is this not implemented in Ruby Jason Roelofs wrote: > Show me a language that does allow you to do this, I've never seen it. > Even then, Ruby doesn't deal with method overloads via parameter > lists, so there's a fundamental reason why it won't work: Clipper,Alaska xBase++. Omitted parameter is treated as nil. They can be tested as nil on the called site. If the value is nil some default value is set. > > def foo(a) > end > > def foo(a, b) > end > > def foo(a, b, c) > end > > foo(1) # => ArgumentError: wrong number of arguments (1 for 3) This is absolutly correct. All these parameters are required. But if I write def foo(a,b=2,c=3) end First parameter is requested others are optional. It would be nice if I could call foo(1,,4). b would have got default value of 2. > > > Ruby 1.9 has keyword arguments, so you'll be able to get past that > easily then. You can fake it in 1.8 with a hash: > > def aProc(options = {}) > a = options[:a] || 5 > b = options[:b] || 6 > c = options[:c] || 7 > print a, b, c > end I know this and hashes are great. Problem is of course libraries that are not written by me. For example. I am using FPDF library which has method Cell. Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='') I would like to align to right and I don't care about border or ln parameter. Cell(1,,'100.000,00',,,'R') would be my preferred solution. And I know FPDF is ugly written library. But it supports using Eastern European characters unlike some other libraries. by TheR -- Posted via http://www.ruby-forum.com/.