Bring Ruby 1.6 Code up to 1.93
Received this error from Ruby 1.93, the code is older (written for and
runs on Ruby 1.6)
makeCores.rb:2136:in block (2 levels) in same_contents': undefined
method>' for nil:NilClass (NoMethodError)
Line 2136 is this if f1.lstat.blksize > 0
class File
def File.same_contents(file1, file2)
return false if !File.exists?(file1) # The files are different if
file1 does not exist
return false if !File.exists?(file2) # The files are different if
file2 does not exist
return true if File.expand_path(file1) == File.expand_path(file2) #
The files are the same if they are the same file
# Otherwise, compare the files contents, one block at a time (First
check if both files are readable)
if !File.readable?(file1) || !File.readable?(file2)
puts "\n>> Warning : Unable to read either xco or input parameters
file"
return false
end
open(file1) do |f1|
open(file2) do |f2|
if f1.lstat.blksize > 0
blocksize = f1.lstat.blksize # Returns the native file system's
block size.
else
blocksize = 4096 # Set to a default value for
platforms that don't support this information (like Windows)
end
same = true
while same && !f1.eof? && !f2.eof?
same = f1.read(blocksize) == f2.read(blocksize)
end
return same
end
end
end
end
I can see that the lstat and blksize methods still exist.
Tried changing lstat to File.lstat the error message changed to:
makeCores.rb:2137:in block (2 levels) in same_contents': undefined
methodFile' for # (NoMethodError)
How do I bring this up to date with Ruby 1.93?
No comments:
Post a Comment