From: Robert Date: 2002-12-29T04:34:10+09:00 Subject: Re: block from string "Rudolf Polzer" schrieb im Newsbeitrag news:slrnb0rii4.fmr.AntiATField_adsgohere@katsuragi.durchnull.ath.cx... > It looks like this can be done using instance_eval. It seems to be > working: > > #!/usr/bin/ruby > > expr = ARGV.shift() > > ((ARGV.length() == 0) ? Dir["..?* .[^.]* *"] : ARGV).each() do |_| > _2 = _.instance_eval(expr) > puts "%s => %s" % [_, _2] > File.rename(_, _2) unless File.exists?(_2) > end > > It looks like I don't need the above approach ('|x| 2*x') any more, but > I'm still interested in it - perhaps it's useful somewhere else. > > And - note the ugly glob pattern. Is there something cleaner for "take > everything from the current directory except . and .."? how about using "next": ( ARGV.empty? ? Dir : ARGV ).each() do |_| next if _ == "." || _ == ".." _2 = _.instance_eval( expr ) puts "%s => %s" % [_, _2] File.rename(_, _2) unless File.exists?(_2) end regards robert