instance method
last
Ruby on Rails 3.0.20
Since v3.0.20Signature
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
-
limitopt = 1
Source
# File activesupport/lib/active_support/core_ext/string/access.rb, line 57
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 57
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in String