method
start_with?

start_with?(*args)
public
Returns true if str starts with a prefix given.
p "hello".start_with?("hell") #=> true # returns true if one of prefix matches. p "hello".start_with?("heaven", "hell") #=> true p "hello".start_with?("heaven", "paradice") #=> false
Register or
log in
to add new notes.
joshuapinter -
May 3, 2012
citizen428 -
May 17, 2012

0 thanks
Starts with a Capital Letter
(or any regular expression you’d like)
'Abracadabra'[0..0] =~ /[A-Z]/ # => true

0 thanks
Starts with capital letter alternative
Just adding an anchor to the regular expression seems simpler (and was faster in my benchmarks, not that that matters much):
'Abracadabra' =~ /^[A-Z]/