How do I find if a string starts with an other string in Ruby?
What the best way to find if a string starts with another in Ruby (without rails)? steenslag puts 'abcdefg'.start_with?('abc') #=> true [edit] This is something I didn't know before this question: start_with takes multiple arguments. 'abcdefg'.start_with?( 'xyz', 'opq', 'ab') Since there are several methods presented here, I wanted to figure out which one was fastest. Using Ruby 1.9.3p362: irb(main):001:0> require 'benchmark' => true irb(main):002:0> Benchmark.realtime { 1.upto(10000000) { "foobar"[/\Afoo/] }} => 12.477248 irb(main):003:0> Benchmark.realtime { 1.upto(10000000) { "foobar" =~ /