instance method rindex

Ruby on Rails 2.3.18

Since v2.3.18 Last seen in v3.2.22.5

Available in: v2.3.18 v3.0.20 v3.1.12 v3.2.22.5

Signature

rindex(needle, offset=nil)

Returns the position needle in the string, counting in codepoints, searching backward from offset or the end of the string. Returns nil if needle isn’t found.

Example:

'Café périferôl'.mb_chars.rindex('é') #=> 6
'Café périferôl'.mb_chars.rindex(/\w/u) #=> 13

Parameters

needle req
offset opt = nil
Source
# File activesupport/lib/active_support/multibyte/chars.rb, line 211
      def rindex(needle, offset=nil)
        offset ||= length
        wrapped_offset = self.first(offset).wrapped_string.length
        index = @wrapped_string.rindex(needle, wrapped_offset)
        index ? (self.class.u_unpack(@wrapped_string.slice(0...index)).size) : nil
      end

Defined in activesupport/lib/active_support/multibyte/chars.rb line 211 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Multibyte::Chars

Type at least 2 characters to search.

↑↓ navigate · open · esc close