Created
February 24, 2011 00:53
-
-
Save kronos/841534 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From c6eecb62ef4b7e94c784586184be779b8e38b2f5 Mon Sep 17 00:00:00 2001 | |
From: Ivan Samsonov <[email protected]> | |
Date: Thu, 24 Feb 2011 03:54:59 +0300 | |
Subject: [PATCH 1/2] Enhance Module#define_method spec | |
--- | |
spec/ruby/core/module/define_method_spec.rb | 10 ++++++++++ | |
1 files changed, 10 insertions(+), 0 deletions(-) | |
diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb | |
index 6c475d0..f136ff6 100644 | |
--- a/spec/ruby/core/module/define_method_spec.rb | |
+++ b/spec/ruby/core/module/define_method_spec.rb | |
@@ -96,6 +96,16 @@ describe "Module#define_method" do | |
lambda { | |
Class.new { define_method(:test, 1234) } | |
}.should raise_error(TypeError) | |
+ | |
+ lambda { | |
+ Class.new { define_method(:test, nil) } | |
+ }.should raise_error(TypeError) | |
+ end | |
+ | |
+ it "raises an ArgumentError when no block is given" do | |
+ lambda { | |
+ Class.new { define_method(:test) } | |
+ }.should raise_error(ArgumentError) | |
end | |
it "accepts a Method (still bound)" do | |
-- | |
1.7.3.2 | |
From 3f1c5499a8c854f310f612d4abb637206279d1f8 Mon Sep 17 00:00:00 2001 | |
From: Ivan Samsonov <[email protected]> | |
Date: Thu, 24 Feb 2011 03:55:08 +0300 | |
Subject: [PATCH 2/2] raise ArgumentError when no block is given in Module#define_method | |
--- | |
kernel/common/module.rb | 8 ++++++-- | |
1 files changed, 6 insertions(+), 2 deletions(-) | |
diff --git a/kernel/common/module.rb b/kernel/common/module.rb | |
index 236dbc5..a97b872 100644 | |
--- a/kernel/common/module.rb | |
+++ b/kernel/common/module.rb | |
@@ -311,8 +311,12 @@ class Module | |
private :filter_methods | |
- def define_method(name, meth = nil, &prc) | |
- meth ||= prc | |
+ def define_method(name, meth = undefined, &prc) | |
+ if meth == undefined and !block_given? | |
+ raise ArgumentError, "tried to create Proc object without a block" | |
+ end | |
+ | |
+ meth = prc if meth == undefined | |
case meth | |
when Proc::Method | |
-- | |
1.7.3.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment