Common implementation for SVCB-compatible resource records.
Removes and returns elements from self
.
With numeric argument index
given, removes and returns the element at offset index
:
a = ['a', 'b', 'c', 'd'] a.slice!(2) # => "c" a # => ["a", "b", "d"] a.slice!(2.1) # => "d" a # => ["a", "b"]
If index
is negative, counts backwards from the end of self
:
a = ['a', 'b', 'c', 'd'] a.slice!(-2) # => "c" a # => ["a", "b", "d"]
If index
is out of range, returns nil
.
With numeric arguments start
and length
given, removes length
elements from self
beginning at zero-based offset start
; returns the removed objects in a new array:
a = ['a', 'b', 'c', 'd'] a.slice!(1, 2) # => ["b", "c"] a # => ["a", "d"] a.slice!(0.1, 1.1) # => ["a"] a # => ["d"]
If start
is negative, counts backwards from the end of self
:
a = ['a', 'b', 'c', 'd'] a.slice!(-2, 1) # => ["c"] a # => ["a", "b", "d"]
If start
is out-of-range, returns nil
:
a = ['a', 'b', 'c', 'd'] a.slice!(5, 1) # => nil a.slice!(-5, 1) # => nil
If start + length
exceeds the array size, removes and returns all elements from offset start
to the end:
a = ['a', 'b', 'c', 'd'] a.slice!(2, 50) # => ["c", "d"] a # => ["a", "b"]
If start == a.size
and length
is non-negative, returns a new empty array.
If length
is negative, returns nil
.
With Range
argument range
given, treats range.min
as start
(as above) and range.size
as length
(as above):
a = ['a', 'b', 'c', 'd'] a.slice!(1..2) # => ["b", "c"] a # => ["a", "d"]
If range.start == a.size
, returns a new empty array:
a = ['a', 'b', 'c', 'd'] a.slice!(4..5) # => []
If range.start
is larger than the array size, returns nil
:
a = ['a', 'b', 'c', 'd'] a.slice!(5..6) # => nil
If range.start
is negative, calculates the start index by counting backwards from the end of self
:
a = ['a', 'b', 'c', 'd'] a.slice!(-2..2) # => ["c"]
If range.end
is negative, calculates the end index by counting backwards from the end of self
:
a = ['a', 'b', 'c', 'd'] a.slice!(0..-2) # => ["a", "b", "c"]
Related: see Methods for Deleting.
Removes and returns the substring of self
specified by the arguments. See String Slices.
A few examples:
string = "This is a string" string.slice!(2) #=> "i" string.slice!(3..6) #=> " is " string.slice!(/s.*t/) #=> "sa st" string.slice!("r") #=> "r" string #=> "Thing"
Returns a substring of self
, or nil
if the substring cannot be constructed.
With integer arguments index
and length
given, returns the substring beginning at the given index
of the given length
(if possible), or nil
if length
is negative or index
falls outside of self
:
s = '0123456789' # => "0123456789" s.byteslice(2) # => "2" s.byteslice(200) # => nil s.byteslice(4, 3) # => "456" s.byteslice(4, 30) # => "456789" s.byteslice(4, -1) # => nil s.byteslice(40, 2) # => nil
In either case above, counts backwards from the end of self
if index
is negative:
s = '0123456789' # => "0123456789" s.byteslice(-4) # => "6" s.byteslice(-4, 3) # => "678"
With Range
argument range
given, returns byteslice(range.begin, range.size)
:
s = '0123456789' # => "0123456789" s.byteslice(4..6) # => "456" s.byteslice(-6..-4) # => "456" s.byteslice(5..2) # => "" # range.size is zero. s.byteslice(40..42) # => nil
In all cases, a returned string has the same encoding as self
:
s.encoding # => #<Encoding:UTF-8> s.byteslice(4).encoding # => #<Encoding:UTF-8>
Replaces some or all of the content of self
with str
, and returns self
. The portion of the string affected is determined using the same criteria as String#byteslice
, except that length
cannot be omitted. If the replacement string is not the same length as the text it is replacing, the string will be adjusted accordingly.
If str_index
and str_length
, or str_range
are given, the content of self
is replaced by str.byteslice(str_index, str_length) or str.byteslice(str_range); however the substring of str
is not allocated as a new string.
The form that take an Integer
will raise an IndexError
if the value is out of range; the Range
form will raise a RangeError
. If the beginning or ending offset does not land on character (codepoint) boundary, an IndexError
will be raised.
The license for this gem.
The license must be no more than 64 characters.
This should just be the name of your license. The full text of the license should be inside of the gem (at the top level) when you build it.
The simplest way is to specify the standard SPDX ID spdx.org/licenses/ for the license. Ideally, you should pick one that is OSI (Open Source Initiative) opensource.org/licenses/ approved.
The most commonly used OSI-approved licenses are MIT and Apache-2.0. GitHub also provides a license picker at choosealicense.com/.
You can also use a custom license file along with your gemspec and specify a LicenseRef-<idstring>, where idstring is the name of the file containing the license text.
You should specify a license for your gem so that people know how they are permitted to use it and any restrictions you’re placing on it. Not specifying a license means all rights are reserved; others have no right to use the code for any purpose.
You can set multiple licenses with licenses=
Usage:
spec.license = 'MIT'
The license(s) for the library.
Each license must be a short name, no more than 64 characters.
This should just be the name of your license. The full text of the license should be inside of the gem when you build it.
See license=
for more discussion
Usage:
spec.licenses = ['MIT', 'GPL-2.0']
Singular accessor for licenses
With no arguments, sets the default visibility for subsequently defined methods to public. With arguments, sets the named methods to have public visibility. String
arguments are converted to symbols. An Array
of Symbols and/or Strings is also accepted. If a single argument is passed, it is returned. If no argument is passed, nil is returned. If multiple arguments are passed, the arguments are returned as an array.
Returns a list of the public instance methods defined in mod. If the optional parameter is false
, the methods of any ancestors are not included.
Similar to instance_method, searches public method only.
Returns a copy of self
with Unicode normalization applied.
Argument form
must be one of the following symbols (see Unicode normalization forms):
:nfc
: Canonical decomposition, followed by canonical composition.
:nfd
: Canonical decomposition.
:nfkc
: Compatibility decomposition, followed by canonical composition.
:nfkd
: Compatibility decomposition.
The encoding of self
must be one of:
Encoding::UTF_8
Encoding::UTF_16BE
Encoding::UTF_16LE
Encoding::UTF_32BE
Encoding::UTF_32LE
Encoding::GB18030
Encoding::UCS_2BE
Encoding::UCS_4BE
Examples:
"a\u0300".unicode_normalize # => "a" "\u00E0".unicode_normalize(:nfd) # => "a "
Related: String#unicode_normalize!
, String#unicode_normalized?
.
Like String#unicode_normalize
, except that the normalization is performed on self
.
Related String#unicode_normalized?
.
Returns true
if self
is in the given form
of Unicode normalization, false
otherwise. The form
must be one of :nfc
, :nfd
, :nfkc
, or :nfkd
.
Examples:
"a\u0300".unicode_normalized? # => false "a\u0300".unicode_normalized?(:nfd) # => true "\u00E0".unicode_normalized? # => true "\u00E0".unicode_normalized?(:nfd) # => false
Raises an exception if self
is not in a Unicode encoding:
s = "\xE0".force_encoding('ISO-8859-1') s.unicode_normalized? # Raises Encoding::CompatibilityError.
Related: String#unicode_normalize
, String#unicode_normalize!
.
Returns the list of public methods accessible to obj. If the all parameter is set to false
, only those methods in the receiver will be listed.
Similar to method, searches public method only.
Invokes the method identified by symbol, passing it any arguments specified. Unlike send, public_send
calls public methods only. When the method is identified by a string, the string is converted to a symbol.
1.public_send(:puts, "hello") # causes NoMethodError