Sorry if I am posting an out of topic, but this problems raised to me when hooking the save process to hold a saved file history stack:
------------- Command, Cmd-S (pre: SaveFile) #!/usr/bin/env ruby
H = "/Users/me/.TM_LastFiles"
files = [] last = ENV["TM_FILEPATH"] files << last
if FileTest.exist?(H) IO.readlines(H).each {|l| if l != last files << l end } end
f = File.new(H, "w") files.each {|l| f.puts l } f.close
puts files --------------------
Why it always ignores the "if" and adds always the current file to the files array??
????
On 12. Feb 2007, at 03:42, Juan wrote:
Sorry if I am posting an out of topic, but this problems raised to me when hooking the save process to hold a saved file history stack:
------------- Command, Cmd-S (pre: SaveFile) #!/usr/bin/env ruby
H = "/Users/me/.TM_LastFiles"
files = [] last = ENV["TM_FILEPATH"] files << last
if FileTest.exist?(H) IO.readlines(H).each {|l| if l != last
This will always be true, since readlines will give you the line in the file including its trailing newline, but TM_FILEPATH has no such.