method
first
v2.3.8 -
Show latest stable
- Class:
ActiveSupport::CoreExtensions::String::Access
first(limit = 1)public
Returns the first character of the string or the first limit characters.
Examples:
"hello".first # => "h" "hello".first(2) # => "he" "hello".first(10) # => "hello"
2Notes
PS
That didn't render properly. Use:
String[1..1]
instead of
String.first
Conflicts with 1.8.7 (and 1.9.1)
"abc".to(0) fails in 1.8.7 and "String"[1..1] should be "String"[0..0] (or "abc"[0...1]). Using to_a breaks in 1.9.1.
I'm using "abc"[0..0]. :(