Kristof Bastiaensen said:
Hi,
[quoted text muted]
Not AFAIK. You can do
content = IO.readlines(file).each {|l| l.chomp!}
or (more efficient)
content = File.open(file) {|io| io.inject([]) {|ar,line| line.chomp!; ar
<< line} }
I think in this case the first is more efficient than the second.
Since chomp! modifies the object inplace, no object gets created.
??? Please read again. The first is less efficient because it iterates
through the lines of the file twice and both use inplace modification
(#chomp!).
what's wrong with IO.foreach?
lines = []
IO.foreach(file){|line| lines << line.chomp!}
or if you have to have one line
IO.foreach(file){|line| (lines||=[]) << line.chomp!}
short, effecient, already built-in - what's not to like ;-)
i like dave's idea of adding traits to ruby though, if we start now maybe one
day ruby will be as good as perl6. i hear it's almost done now!
-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
===============================================================================