instance method first

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.3.18

Available 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

limit opt = 1
Source
# File activesupport/lib/active_support/core_ext/string/access.rb, line 43
          def first(limit = 1)
            mb_chars[0..(limit - 1)].to_s
          end

Defined in activesupport/lib/active_support/core_ext/string/access.rb line 43 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::CoreExtensions::String::Access

Type at least 2 characters to search.

↑↓ navigate · open · esc close