Class: File

Inherits:
Object show all
Defined in:
lib/sitefuel/extensions/FileComparison.rb

Class Method Summary (collapse)

Class Method Details

+ (Boolean) equivalent?(a, b)

gives true if one of the paths is the ending of another path

File.equivalent?('b/a.rb', 'a.rb')  # ==> true
File.equivalent?('c/b/a.rb', 'c/a.rb')  # ==> false

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/sitefuel/extensions/FileComparison.rb', line 17

def self.equivalent?(a, b)
  list = [
    File.expand_path(a, '/').split(File::SEPARATOR)[1 .. -1],
    File.expand_path(b, '/').split(File::SEPARATOR)[1 .. -1]
  ].sort {|l,r| l.length <=> r.length }.reverse
  list.first.ends_with? list.last
end