class SubString

Child class of SubObject for String: SubString

See for detail the full reference in the top page SubString and in Github and also SubObject and that in Github

@author Masa Sakano (Wise Babel Ltd)

Constants

TO_SOURCE_METHOD

Symbol of the method that projects to (returns) the original-like instance; e.g., :to_str for String. The value should be overwritten in the child class of {SubObject}, namely this class {SubString} in this case.

Public Class Methods

new(source, pos=0, size=nil, attr: nil) click to toggle source

Returns a new instance of SubString equivalent to source[ pos, size ]

Difference from the original SubObject is the defaults are set for the second and third parameters.

If the third parameter is nil, it is set as the maximum size possible counted from pos (the starting position)

@param source [String] @param pos [Integer] Starting character index position. @param size [Integer, nil] Size of the substring to make. @param attr: [Object] user-specified arbitrary object

Calls superclass method
# File lib/sub_string.rb, line 33
def initialize(source, pos=0, size=nil, attr: nil)
  size ||= ((pos >= 0) ? source.size - pos : -pos)
  super source, pos, size, attr: attr
end