Что я пытаюсь сделать, это выяснить, является ли какая-либо папка дочерней / родительской папкой или не связана.
Есть ли какая-либо функция в Ruby File API ?если не как это выяснить?
Например:
real_path_1 = "/Users/amr/Code/xx/zz"
real_path_2 = "/Users/amr/Code/"
# when I have to compare between these paths like:
f_level(real_path_1, real_path_2)
# it should return +2
# that means real_path_1 is **parent** of real_path_2
# with 2 levels depth
Еще один пример:
real_path_1 = "/Users/amr/Code/"
real_path_2 = "/Users/amr/Code/foo/bar/inside"
# when I have to compare between these paths like:
f_level(real_path_1, real_path_2)
# it should return -3
# that means real_path_1 is **child** of real_path_2
# with 3 levels depth
Другой пример:
real_path_1 = "/Users/amr/Code/"
real_path_2 = "/Users/amr/Code/"
# when I have to compare between these paths like:
f_level(real_path_1, real_path_2)
# it should return 0
# that means real_path_1 is **same level** as real_path_2
Когда возвращается ноль :
real_path_1 = "/Users/other/Code/" # or "/folder2/"
real_path_2 = "/Users/amr/Code/" # or "/folder1/"
# when I have to compare between these paths like:
f_level(real_path_1, real_path_2)
# it should return nil
# that means real_path_1 is **not at same level** as real_path_2