aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/plum/binary_string.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/plum/binary_string.rb b/lib/plum/binary_string.rb
index 2d3ed76..72b38b1 100644
--- a/lib/plum/binary_string.rb
+++ b/lib/plum/binary_string.rb
@@ -54,6 +54,21 @@ module Plum
force_encoding(Encoding::BINARY)
slice!(0, count)
end
+
+ def each_byteslice(n, &blk)
+ if block_given?
+ pos = 0
+ while pos < self.bytesize
+ yield byteslice(pos, n)
+ pos += n
+ end
+ else
+ Enumerator.new do |y|
+ each_byteslice(n) {|ss| y << ss }
+ end
+ # I want to write `enum_for(__method__, n)`!
+ end
+ end
end
end
end