This is a method which creates an array of all possible consecutive substrings from a string:def get_seperated_tokens(query)  result = []  length = query.split.count  tokens = query.downcase.strip.split(' ')  length.times do |i|    length.times do |j|      result << tokens[i..j].join(' ') if j >= i    end  end  resultendTo get a better idea I have added rspec for it:describe #get_seperated_tokens do  it returns an array of seperated tokens do    query = 'ruby is awesome'    result = ['ruby','is', 'awesome', 'ruby is', 'is awesome','ruby is awesome']    expect(get_seperated_tokens(query)).to include(*result)  end  it returns an array of seperated tokens do    query = 'red blue iphones'    result = ['red','blue', 'iphones', 'red blue', 'blue iphones','red blue iphones']    expect(get_seperated_tokens(query)).to include(*result)  endendHow can this be made more idiomatic?
Creating consecutive words from a string
strings;ruby
As @Michael Szyndel mentioned in a comment, Array#combination is the more appropriate method to use.def get_separated_tokens query  tokens = query.split  (0..tokens.size).to_a.combination(2).map{ |i,j| tokens[i...j].join   }end