"Martin DeMello" <martindemello / yahoo.com> schrieb im Newsbeitrag news:eTFvc.621056$Pk3.280803 / pd7tw1no... > Robert Klemme <bob.news / gmx.net> wrote: > > "Martin DeMello" <martindemello / yahoo.com> schrieb im Newsbeitrag > > news:0JEvc.620827$Pk3.157220 / pd7tw1no... > > > I'm writing a small wrapper around ruby, meant to be used as part of a > > > unix pipeline filter - e.g. > > > > > > ls -l | rbx 'cols(8,4).mapf(:to_s).formatrow(" ", 30, 8).endl' > > > > I'd perfer to have something in front of cols() that does the splitting - > > otherwise it's always space separated which might limit usefulness. > > Hm - I was trying to avoid an extraneous 'split', since cols always > requires one. Maybe check if the first argument is a string and split on > that, otherwise split on space. I'd find it more clean if it was not a parameter to cols but an extra operation before. You can leave it as it is with two changes if you just add method cols to Array (or enumerable). Then you can use the old behavior (i.e. implicit split by white space) and additionally you can use String#split to do the splitting. > > > class Array > > > def take_while! > > > > This name is misleading since it suggests that array is manipulated in > > place. Better remove the "!". > > It is - I'm using 'shift'. I figured optionparse was overkill since I > just wanted to pass the options along to ruby. Oh, yeah. Sorry, I overlooked that. > > Why do you spawn an extra process here? IMHO that's superfluous. If you > > put the command into a block, your main loop will look like this: > > Mostly because it started life as a shellscript, and then migrated over > when I coldn't figure out how to do option parsing properly :) "Historic reasons". :-) > > while ( line = gets ) > > line.chomp! > > command.call line > > end > > > > To do that you just need > > > > command = eval %Q{ lambda {|line| puts line.instance_eval( > > '#{ARGV.shift}' ) } } > > But how will that let us pass options to the ruby interpreter? Which options do you need to pass on? If it's not too esoteric, you might be able to set them via global variables. Regards robert