lib/hanami/utils/string.rb
def rsub(pattern, replacement)
        if i = rindex(pattern)
          s    = @string.dup
          s[i] = replacement
          self.class.new s
        else
          self
        end
      end
# Replace the rightmost match of <tt>pattern</tt> with <tt>replacement</tt>
#
# If the pattern cannot be matched, it returns the original string.
#
# This method does NOT mutate the original string.
#
# @param pattern [Regexp, String] the pattern to find
# @param replacement [String, Hanami::Utils::String] the string to replace
#
# @return [Hanami::Utils::String] the replaced string
#
# @since 0.6.0
#
# @example
#   require 'hanami/utils/string'
#
#   string = Hanami::Utils::String.new('authors/books/index')
#   result = string.rsub(/\//, '#')
#
#   puts string
#     # => #<Hanami::Utils::String:0x007fdb41233ad8 @string="authors/books/index">
#
#   puts result
#     # => #<Hanami::Utils::String:0x007fdb41232ed0 @string="authors/books#index">
Replace the rightmost match of pattern with replacement
If the pattern cannot be matched, it returns the original string.

This method does NOT mutate the original string.
Replace the rightmost match of pattern with replacement If the pattern cannot be matched it returns the original string . This method does NOT mutate the original string .
def rsub(pattern, replacement)
        if i = rindex(pattern)
          s    = @string.dup
          s[i] = replacement
          self.class.new s
        else
          self
        end
      end
def rsub ( pattern , replacement ) if i = rindex ( pattern ) s = @string . dup s [ i ] = replacement self . class . new s else self end end
Replace the rightmost match of <tt>pattern</tt> with <tt>replacement</tt>
If the pattern cannot be matched, it returns the original string.
Replace the rightmost match of <tt > pattern< / tt > with <tt > replacement< / tt > If the pattern cannot be matched it returns the original string .
the replaced string
the replaced string
Hanami::Utils::String
pattern
the pattern to find
the pattern to find
replacement
the string to replace
the string to replace
since
None
example
require 'hanami/utils/string' string = Hanami::Utils::String.new('authors/books/index') result = string.rsub(/\//, '#') puts string # => # puts result # => #
require ' hanami / utils / string ' string = Hanami :: Utils :: String . new ( ' authors / books / index ' ) result = string . rsub ( / \ // ' # ' ) puts string # = > # puts result # = > #