Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v3.2.13) is shown here.
insert(offset, fragment)
public
Inserts the passed string at specified codepoint offsets.
Example:
'Café'.mb_chars.insert(4, ' périferôl').to_s
# File activesupport/lib/active_support/multibyte/chars.rb, line 123
def insert(offset, fragment)
unpacked = Unicode.u_unpack(@wrapped_string)
unless offset > unpacked.length
@wrapped_string.replace(
Unicode.u_unpack(@wrapped_string).insert(offset, *Unicode.u_unpack(fragment)).pack('U*')
)
else
raise IndexError, "index #{offset} out of string"
end
self
end