私は小さなスクリプトを作成していますが、パス(たとえば文字列)が別のパス(別の文字列)の外にあるかどうかをテストする方法を知る必要があります。例えば:
/some/path
内側にあるので/some/path/file.rb
戻りますが、外側にあるので戻ります。false
file.rb
/some/path
/some/path
/some/file.rb
true
file.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