Skip to content
Permalink
Browse files

Merge pull request #719 from krekoten/moduel_define_method

Module#define_method
  • Loading branch information
alex committed May 20, 2013
2 parents ae83769 + d9011f4 commit 97c4cc3980d5aa42033dcf879b2d1a1065c87535
@@ -0,0 +1 @@
fails:The -n command line option
@@ -0,0 +1 @@
fails:the -F command line option
@@ -1,3 +1,10 @@
fails:Array#shuffle attempts coercion via #to_hash
fails:Array#shuffle uses default random generator
fails:Array#shuffle uses given random generator
fails:Array#shuffle calls #rand on the Object passed by the :random key in the arguments Hash
fails:Array#shuffle ignores an Object passed for the RNG if it does not define #rand
fails:Array#shuffle accepts a Float for the value returned by #rand
fails:Array#shuffle calls #to_f on the Object returned by #rand
fails:Array#shuffle raises a RangeError if the random generator returns a value less than 0.0
fails:Array#shuffle raises a RangeError if the random generator returns a value equal to 1.0
fails:Array#shuffle raises a RangeError if the random generator returns a value greater than 1.0
@@ -3,3 +3,14 @@ fails:File.open opens file when call with a block (basic case)
fails:File.open opens a file with mode string and block
fails:File.open opens the file when passed mode, num and permissions
fails:File.open opens a file with mode num and block
fails:File.open opens the file when passed mode, num, permissions and block
fails:File.open creates the file and returns writable descriptor when called with 'w' mode and r-o permissions
fails:File.open opens the existing file, does not change permissions even when they are specified
fails:File.open creates a new write-only file when invoked with 'w' and '0222'
fails:File.open opens a file that no exists when use File::WRONLY mode
fails:File.open opens a file that no exists when use File::RDONLY mode
fails:File.open opens a file that no exists when use 'r' mode
fails:File.open opens a file that no exists when use File::EXCL mode
fails:File.open opens a file that no exists when use File::NONBLOCK mode
fails:File.open opens a file that no exists when use File::TRUNC mode
fails:File.open opens a file that no exists when use File::NOCTTY mode
@@ -1,22 +1 @@
fails:passed { |a, b = 1| } creates a method that raises an ArgumentError when passed zero arguments
fails:passed { |a, b = 1| } creates a method that raises an ArgumentError when passed three arguments
fails:Module#define_method when given an UnboundMethod adds the new method to the methods list
fails:Module#define_method raises a TypeError when the given method is no Method/Proc
fails:Module#define_method raises a RuntimeError if frozen
fails:Module#define_method is private
fails:Module#define_method returns a Proc
fails:Module#define_method passed { } creates a method that raises an ArgumentError when passed one argument
fails:Module#define_method passed { } creates a method that raises an ArgumentError when passed two arguments
fails:Module#define_method passed { || } creates a method that raises an ArgumentError when passed one argument
fails:Module#define_method passed { || } creates a method that raises an ArgumentError when passed two arguments
fails:Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed zero arguments
fails:Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed zero arguments and a block
fails:Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed two arguments
fails:Module#define_method passed { |a, *b| } creates a method that raises an ArgumentError when passed zero arguments
fails:Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed zero arguments
fails:Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed one argument
fails:Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed one argument and a block
fails:Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed three arguments
fails:Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed zero arguments
fails:Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument
fails:Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument and a block
@@ -399,18 +399,26 @@ def method_append_features(self, space, w_mod):
w_mod.include_module(space, module)

@classdef.method("define_method", name="symbol")
@check_frozen()
def method_define_method(self, space, name, w_method=None, block=None):
if w_method is not None:
if space.is_kind_of(w_method, space.w_method):
w_method = space.send(w_method, "unbind")

if space.is_kind_of(w_method, space.w_unbound_method):
self.define_method(space, name, DefineMethodMethod(name, w_method))
return w_method
elif space.is_kind_of(w_method, space.w_proc):
assert isinstance(w_method, W_ProcObject)
self.define_method(space, name, DefineMethodBlock(name, w_method))
return w_method.copy(space, is_lambda=True)
else:
raise space.error(space.w_TypeError,
"wrong argument type %s (expected Proc/Method)" % space.obj_to_s(space.getclass(w_method))
)
elif block is not None:
self.define_method(space, name, DefineMethodBlock(name, block))
return block.copy(space, is_lambda=True)
else:
raise space.error(space.w_ArgumentError, "tried to create Proc object without a block")

0 comments on commit 97c4cc3

Please sign in to comment.
You can’t perform that action at this time.