From: Daniel Berger Date: 2008-10-30T06:12:13+09:00 Subject: Re: Named arguments gem On Oct 29, 2:17 pm, Macario Ortega wrote: > Daniel Berger wrote: > > On Oct 27, 9:58 pm, Macario Ortega wrote: > >> >> This works fine. > >> >> Regards, > >> Mine is just hosted at github > > >> If you want to give it a try you have to downolad it fromhttp://github.com/maca/namedarguments/tree/master/ > > >> and install acording to the Readme file. > > > Aha, thanks, that explains it. > > > Could I convince you to change the name then? I mean, you could do > > more than named arguments couldn't you? Also, it would eliminate the > > confusion. > > > Could you also add some sort of optional pseudo-static typing that > > would automatically raise a TypeError if the wrong type was given? > > > class Example > >   def test_method(Fixnum alpha = 1, String beta = "world") > >     [alpha, beta] > >   end > > end > > > ex = Example.new > > ex.test_method(:beta => "Hello", :alpha => 3) # ok > > ex.test_method(:alpha => "Hello", :beta => 3) # TypeError > > > If so, consider it a feature request. :) > > > Regards, > > > Dan > > Yeah, I think I will change the gem name to avoid confusion, about the > semi-static syntax you propose is not very ruby-ish, the ruby > interpreter would complain if you define a method like you propose but > you could define your method like this: > > class Example >   def test_method( alpha = 1, beta = "wold) >     raise TypeError.new("alpha must be an Integer") unless > alpha.instance_of?(Integer) >     ...do stuff with alpha and beta >   end >   named_args_for :test_method > end Oh, I realize there are ways to get the same behavior. But, I'd like that notation. What I'm ultimately hoping for is that, if you support that notation, we could use RubyInline behind the scenes and do automatic optimization: http://segment7.net/projects/ruby/inline_optimization.html What do you think? Regards, Dan