malloc 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/malloc_ext.rb +9 -0
- data/test/tc_malloc.rb +7 -0
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/malloc_ext.rb
CHANGED
@@ -90,6 +90,15 @@ module Hornetseye
|
|
90
90
|
"Malloc(#{@size})"
|
91
91
|
end
|
92
92
|
|
93
|
+
# Duplicate object
|
94
|
+
#
|
95
|
+
# @return [Malloc] A new malloc object with a copy of the data.
|
96
|
+
def dup
|
97
|
+
retval = Malloc.new @size
|
98
|
+
retval.write self
|
99
|
+
retval
|
100
|
+
end
|
101
|
+
|
93
102
|
# Display information about this object
|
94
103
|
#
|
95
104
|
# @example Displaying information about a Malloc object
|
data/test/tc_malloc.rb
CHANGED
@@ -39,6 +39,13 @@ class TC_Malloc < Test::Unit::TestCase
|
|
39
39
|
assert_equal 'Malloc(32)', Malloc.new( 32 ).to_s
|
40
40
|
end
|
41
41
|
|
42
|
+
def test_dup
|
43
|
+
m = Malloc.new( 3 )
|
44
|
+
m.write 'abc'
|
45
|
+
m.dup.write 'def'
|
46
|
+
assert_equal 'abc', m.read( 3 )
|
47
|
+
end
|
48
|
+
|
42
49
|
def test_read_write
|
43
50
|
m = Malloc.new 6
|
44
51
|
assert_equal 'abcdef', m.write( 'abcdef' )
|