How do I find if a string starts with another string in Ruby?

Guillaume Coté picture Guillaume Coté · Nov 12, 2010 · Viewed 102.9k times · Source

What the best way to find if a string starts with another in Ruby (without rails)?

Answer

steenslag picture steenslag · Nov 12, 2010
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')