From: "Berger, Daniel" Date: 2005-10-21T23:32:20+09:00 Subject: Re: A comparison by example of keyword argument styles > -----Original Message----- > From: Trans [mailto:transfire@gmail.com] > Sent: Friday, October 21, 2005 8:12 AM > To: ruby-talk ML > Subject: Re: A comparison by example of keyword argument styles > Perhaps we should just sing a song and "Let's Call The Whole > Thing Off". Heh. Thought about it. > If keywords integrate the interface too tightly > with the code, then why tie them to the interface? Also, I > imagine there many be many more keyword arguments then > ordered args, this will make for some very LONG constructors: > > def stadium( height:, seating_capacity:, location:, color:, > sports:, concessions:, extra_features:, indoor:, yadayadayada: ) > > So maybe just treat named parameters like blocks. You can > have em or not. But you don't need to define them in the > interface. Currently I do a lot of > > def( *args ) > keys = args.last.is_a?(Hash) ? args.pop : {} > a,b,c = *args > > If I could just do > > def( a, b, c, **keys ) > ... > > I'd be happy enough. I'm glad you brought this example up. What do you do when you have a ton of accessors in your class? I have just such a case with the Format class in the spreadsheet package, where you have "font_name", "font_size", "border_color", etc. About 30 accessors I think. The solution here is NOT keywords arguments (regardless of implementation), where you would end up with ridiculously long constructors, as you mentioned. It's the old "yield self if block_given?" trick: class Format attr_accessor :font_color, :font_size, :bold # ... def initialize yield self if block_given? end end format = Format.new do |f| f.font_color = "blue" f.font_size = 10 f.bold = true ... end Regards, Dan