Cut array after key in Ruby -
i need cut array after key in ruby, example:
=> ["foo", "bar", "baz", "oof", "rab", "zab"] # cut after "baz" => ["baz", "oof", "rab", "zab"] # result
it's possible do? how can that?
yes, specify range index -1(last element):
arr = ["foo", "bar", "baz", "oof", "rab", "zab"] arr[arr.index("baz")..-1] # => ["baz", "oof", "rab", "zab"]
Comments
Post a Comment