From: "trans. (T. Onoma)" Date: 2004-10-05T00:02:04+09:00 Subject: Re: Too Many Ways? On Monday 04 October 2004 10:12 am, Gavin Sinclair wrote: > On Tuesday, October 5, 2004, 12:08:42 AM, trans. wrote: > >> So in an ideal world I'd have > >> > >> def foo(a,b) # block forbidden, raise exception if you pass one > >> def foo(a,b,&c) # block required, raise exception if it's missing > >> def foo(a,b,&c=nil) # block optional > >> > >> That syntax would also allow a 'default block': > >> > >> def foo(a,b,&c=proc{|x| $stderr.puts x}) > > > > This last should be allowed anyway, me thinks too. > > That's bad style, IMO. I'd prefer to read this: > > def foo(a, b, &c=nil) > c ||= lambda { |x| ... } > ... > end Better: c = lambda { |x| ... } def foo(a, b, &c=c) ... end Why? Well, there seems to be a general aversion to lambdas in method arguments. Probably b/c a) the Kernel#proc method is needed and b) increased bracketing, i.e. cases like: def foo(a, b, &c=proc{|x| $stderr.puts x # and more # to do }, &d=proc{|x| $stdout.puts x # and maybe # another }) But following your preference to its logical conclusion: def foo(a=nil, b=nil, &c=nil) a ||= "foo" b ||= "bar" c ||= lambda { |x| ... } ... end T.