Skip to content

Commit

Permalink
Added shortcut for Malloc.new
Browse files Browse the repository at this point in the history
  • Loading branch information
wedesoft committed Aug 31, 2010
1 parent 7995829 commit 3aaacae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/malloc_ext.rb
Expand Up @@ -52,6 +52,8 @@ class << self
#
# @param [Integer] size Number of bytes to allocate.
# @return [Malloc] A new Malloc object.
#
# @see Malloc
def new( size )
retval = orig_new size
retval.instance_eval { @size = size }
Expand Down Expand Up @@ -183,4 +185,22 @@ def write( string )

end

# Shortcut for instantiating Malloc object
#
# @example Create malloc object
# require 'malloc'
# include Hornetseye
# m = Malloc 4
# # Malloc(4)
#
# @param [Integer] size Number of bytes to allocate.
# @return [Malloc] A new Malloc object.
#
# @see Malloc.new
def Malloc( size )
Malloc.new size
end

module_function :Malloc

end
1 change: 1 addition & 0 deletions test/tc_malloc.rb
Expand Up @@ -21,6 +21,7 @@ class TC_Malloc < Test::Unit::TestCase

def test_new
assert_nothing_raised { Hornetseye::Malloc.new 32 }
assert_nothing_raised { Hornetseye::Malloc 32 }
assert_raise( ArgumentError ) { Hornetseye::Malloc.new }
end

Expand Down

0 comments on commit 3aaacae

Please sign in to comment.