instance method last

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

last(limit = 1)

Returns the last character of the string or the last limit characters.

Examples:

"hello".last     # => "o"
"hello".last(2)  # => "lo"
"hello".last(10) # => "hello"

Parameters

limit opt = 1
Source
# File activesupport/lib/active_support/core_ext/string/access.rb, line 59
          def last(limit = 1)
            if limit == 0
              ''
            elsif limit >= size
              self
            else
              mb_chars[(-limit)..-1].to_s
            end
          end

Defined in activesupport/lib/active_support/core_ext/string/access.rb line 59 · 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