Class: LazyString::LazySubString

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy-string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#sizeObject (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_strObject Also known as: to_s



28
29
30
# File 'lib/lazy-string.rb', line 28

def to_str
  @value[@start, @size].to_str
end