Paul Lutus wrote:
> Xan Xann wrote:
> 
>> Paul Lutus wrote:
> 
> / ...
> 
>>> Also "not tested!". That may seem obvious at this point.
>> 
>> It does not work!!!:
>> wiki.rb:10: parse error, unexpected kEND
> 
> My original code was actually pseudo-code, unbeknownst to me. :)
> 
> ------------------------------------------
> 
> #!/usr/bin/ruby
> 
> def substitute(source,dest,find,replace)
>   data = File.read(source)
>   result = data.gsub(/#{find}/,replace)
>   File.open(dest,"w") { |f| f.write(result) } if data != result
> end
> 
> substitute("temp.txt","result.txt","i","x")
> 
> temp.txt = "This is a test line."
> 
> result.txt = "Thxs xs a test lxne."
> 
> Tested, which I should have done in the first place.

I get this error:

wiki.rb:7:in `read': can't convert File into String (TypeError)
        from wiki.rb:7:in `substitute'
        from wiki.rb:12


with code:

require 'fileutils'

        f1 = File.open("original.txt")
        f2 = File.open("canviada.txt")

def substitute(source,dest,find,replace)
  data = File.read(source)
  result = data.gsub(/#{find}/,replace)
  File.open(dest,"w") { |f| f.write(result) } if data != result
end

substitute(f1,f2,"ol","ur")


What happens?
Thanks,
Xan.

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