Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Malloc#dup

  • Loading branch information...
commit 7492faf2171580a0e4965824cce50863c7fdd017 1 parent c7ba946
@wedesoft authored
Showing with 17 additions and 1 deletion.
  1. +1 −1  Rakefile
  2. +9 −0 lib/malloc_ext.rb
  3. +7 −0 test/tc_malloc.rb
View
2  Rakefile
@@ -7,7 +7,7 @@ require 'rake/loaders/makefile'
require 'rbconfig'
PKG_NAME = 'malloc'
-PKG_VERSION = '1.2.0'
+PKG_VERSION = '1.3.0'
CXX = ENV[ 'CXX' ] || 'g++'
STRIP = ENV[ 'STRIP' ] || 'strip'
RB_FILES = FileList[ 'lib/**/*.rb' ]
View
9 lib/malloc_ext.rb
@@ -90,6 +90,15 @@ def inspect
"Malloc(#{@size})"
end
+ # Duplicate object
+ #
+ # @return [Malloc] A new malloc object with a copy of the data.
+ def dup
+ retval = Malloc.new @size
+ retval.write self
+ retval
+ end
+
# Display information about this object
#
# @example Displaying information about a Malloc object
View
7 test/tc_malloc.rb
@@ -39,6 +39,13 @@ def test_to_s
assert_equal 'Malloc(32)', Malloc.new( 32 ).to_s
end
+ def test_dup
+ m = Malloc.new( 3 )
+ m.write 'abc'
+ m.dup.write 'def'
+ assert_equal 'abc', m.read( 3 )
+ end
+
def test_read_write
m = Malloc.new 6
assert_equal 'abcdef', m.write( 'abcdef' )
Please sign in to comment.
Something went wrong with that request. Please try again.