こんにちは、次のようにRuby配列を分割する小さなruby関数があります:-
def rearrange arr,from,to
sidx = arr.index from
eidx = arr.index to
arr[sidx] = arr[sidx+1..eidx]
end
arr= ["Red", "Green", "Blue", "Yellow", "Cyan", "Magenta", "Orange", "Purple", "Pink", "White", "Black"]
start = "Yellow"
stop = "Orange"
rearrange arr,start,stop
puts arr.inspect
#=> ["Red", "Green", "Blue", ["Cyan", "Magenta", "Orange"], "Cyan", "Magenta", "Orange", "Purple", "Pink", "White", "Black"]
検索の開始と停止で正規表現を使用する必要があります。
開始 = "/Yell/"
停止 = "/Ora/"
Rubyでこれを行う簡単な方法はありますか?