Class: SubString
- Inherits:
-
SubObject
- Object
- SubObject
- SubString
- Defined in:
- lib/sub_string.rb
Overview
Constant Summary collapse
- 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.
:to_str
Instance Method Summary collapse
-
#initialize(source, pos = 0, size = nil, attr: nil) ⇒ SubString
constructor
Returns a new instance of SubString equivalent to source[ pos, size ].
Constructor Details
#initialize(source, pos = 0, size = nil, attr: nil) ⇒ SubString
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)
34 35 36 37 |
# File 'lib/sub_string.rb', line 34 def initialize(source, pos=0, size=nil, attr: nil) size ||= ((pos >= 0) ? source.size - pos : -pos) super source, pos, size, attr: attr end |