Leo M. wrote in post #978439:
> file = File.open("/R/testo.txt", "r")
>
> text = (file.each {|line| print line }).to_s
>
> text.to_s
> text.gsub!(/o/,"*")

Processing one line at a time is a good idea because it lets you handle 
files bigger than will fit into memory.

This can be as simple as:

file = File.open("/R/testo.txt")
file.each { |line| print line.gsub!(/o/,"*") }

Or better, like this:

File.open("/R/testo.txt") do |file|
  file.each { |line| print line.gsub!(/o/,"*") }
end

The second version will automatically close the file at the end of the 
block.

I'd prefer "each_line" to "each". Not only is it clearer, but 'each' for 
strings was removed from ruby 1.9 (although oddly not from files)

-- 
Posted via http://www.ruby-forum.com/.