Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added main#define_method. #2921

Merged
merged 2 commits into from

2 participants

@razielgn

Fixes #2886.

@YorickPeterse YorickPeterse merged commit 74e9714 into rubinius:master
@razielgn razielgn deleted the unknown repository branch
@razielgn

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 5, 2014
  1. @razielgn
  2. @razielgn

    Added main#define_method.

    razielgn authored
This page is out of date. Refresh to see the latest.
Showing with 44 additions and 0 deletions.
  1. +6 −0 kernel/common/main.rb
  2. +38 −0 spec/ruby/core/main/define_method_spec.rb
View
6 kernel/common/main.rb
@@ -21,6 +21,12 @@ def private(*methods)
Object
end
+ def define_method(*args, &block)
+ Rubinius.privately do
+ Object.define_method(*args, &block)
+ end
+ end
+
def to_s
"main"
end
View
38 spec/ruby/core/main/define_method_spec.rb
@@ -0,0 +1,38 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+
+ruby_version_is '2.0' do
+ script_binding = binding
+
+ describe "main#define_method" do
+ before :each do
+ @code = 'define_method(:boom) { :bam }'
+ end
+
+ after :each do
+ Object.send :remove_method, :boom
+ end
+
+ it 'creates a public method in TOPLEVEL_BINDING' do
+ eval @code, TOPLEVEL_BINDING
+ Object.should have_method :boom
+ end
+
+ it 'creates a public method in script binding' do
+ eval @code, script_binding
+ Object.should have_method :boom
+ end
+
+ ruby_version_is '2.0'...'2.1' do
+ it 'returns a Proc' do
+ eval(@code, TOPLEVEL_BINDING).is_a?(Proc).should be_true
+ end
+ end
+
+ ruby_version_is '2.1' do
+ it 'returns the method name as symbol' do
+ eval(@code, TOPLEVEL_BINDING).should equal :boom
+ end
+ end
+ end
+end
Something went wrong with that request. Please try again.