instance method
first
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
first(limit = 1)
Returns the first character of the string or the first limit characters.
Examples:
"hello".first # => "h" "hello".first(2) # => "he" "hello".first(10) # => "hello"
Parameters
-
limitopt = 1
Source
# File activesupport/lib/active_support/core_ext/string/access.rb, line 43
def first(limit = 1)
if limit == 0
''
elsif limit >= size
self
else
mb_chars[0...limit].to_s
end
end
Defined in activesupport/lib/active_support/core_ext/string/access.rb line 43
· View on GitHub
· Improve this page
· Find usages on GitHub