私は小さなスクリプトを作成していますが、パス(たとえば文字列)が別のパス(別の文字列)の外にあるかどうかをテストする方法を知る必要があります。例えば:
/some/path内側にあるので/some/path/file.rb戻りますが、外側にあるので戻ります。falsefile.rb/some/path/some/path/some/file.rbtruefile.rb/some/path
前もって感謝します!
使用できますString#starts_with?:
path = '/some/path'
file = '/some/path/file.rb'
file.starts_with?(path) #=> true
と:
path = '/some/path'
file = '/some/file.rb'
file.starts_with?(path) #=> false