start_with?(...) public

Returns true if str starts with the prefix given.

Show source
Register or log in to add new notes.
May 3, 2012
0 thanks

Starts with a Capital Letter

(or any regular expression you’d like)

'Abracadabra'[0..0] =~ /[A-Z]/       # => true
May 17, 2012
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]/