Class: LazyString::LazySubString
- Inherits:
-
Object
- Object
- LazyString::LazySubString
- Defined in:
- lib/lazy-string.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
(also: #length)
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #[](*args) ⇒ Object
-
#initialize(value, start, size) ⇒ LazySubString
constructor
A new instance of LazySubString.
- #to_str ⇒ Object (also: #to_s)
Constructor Details
#initialize(value, start, size) ⇒ LazySubString
Returns a new instance of LazySubString.
12 13 14 15 16 |
# File 'lib/lazy-string.rb', line 12 def initialize(value, start, size) @start = start @size = size @value = value end |
Instance Attribute Details
#size ⇒ Object (readonly) Also known as: length
Returns the value of attribute size.
33 34 35 |
# File 'lib/lazy-string.rb', line 33 def size @size end |
Instance Method Details
#[](*args) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/lazy-string.rb', line 18 def [](*args) if args.size == 2 start = args[0] length = args[1] return @value[@start + start, length] else raise NotImplementedError end end |
#to_str ⇒ Object Also known as: to_s
28 29 30 |
# File 'lib/lazy-string.rb', line 28 def to_str @value[@start, @size].to_str end |