Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ole/support.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#each_chunk(size) ⇒ Object



20
21
22
# File 'lib/ole/support.rb', line 20

def each_chunk size
	(length / size.to_f).ceil.times { |i| yield self[i * size, size] }
end

#indexes(string) ⇒ Object

plural of String#index. returns all offsets of string. rename to indices?

note that it doesn’t check for overlapping values.



15
16
17
18
# File 'lib/ole/support.rb', line 15

def indexes string
	# in some ways i'm surprised that $~ works properly in this case...
	to_enum(:scan, /#{Regexp.quote string}/m).map { $~.begin 0 }
end