From: Macario Ortega Date: 2008-10-30T05:17:24+09:00 Subject: Re: Named arguments gem 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 -- Posted via http://www.ruby-forum.com/.