prepend 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -1
- data/Rakefile +2 -2
- data/ext/prepend/prepend.c +14 -2
- data/lib/prepend/version.rb +1 -1
- data/test/test.rb +45 -0
- metadata +5 -4
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -29,8 +29,8 @@ specification = Gem::Specification.new do |s|
|
|
29
29
|
s.extensions = ["ext/prepend/extconf.rb"]
|
30
30
|
s.files = ["Rakefile", "README.markdown", "CHANGELOG",
|
31
31
|
"lib/prepend.rb", "lib/prepend/version.rb"] +
|
32
|
-
|
33
|
-
FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
|
32
|
+
# ["lib/1.9/prepend.so", "lib/1.8/prepend.so"] +
|
33
|
+
FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "test/*.rb"].to_a
|
34
34
|
end
|
35
35
|
|
36
36
|
Rake::GemPackageTask.new(specification) do |package|
|
data/ext/prepend/prepend.c
CHANGED
@@ -12,7 +12,13 @@ class_mod_wrapper_to_s(VALUE self)
|
|
12
12
|
static VALUE
|
13
13
|
klass_to_s(VALUE self)
|
14
14
|
{
|
15
|
-
|
15
|
+
VALUE name;
|
16
|
+
if (NIL_P(rb_mod_name(self)))
|
17
|
+
name = rb_str_new2("Anon");
|
18
|
+
else
|
19
|
+
name = rb_mod_name(self);
|
20
|
+
|
21
|
+
return rb_str_concat(name, rb_str_new2("*"));
|
16
22
|
}
|
17
23
|
|
18
24
|
static VALUE
|
@@ -20,6 +26,7 @@ rb_prepend_module(VALUE klass, VALUE module)
|
|
20
26
|
{
|
21
27
|
/* create wrapper module to hold current class's M_TBL */
|
22
28
|
VALUE class_mod_wrapper = rb_module_new();
|
29
|
+
VALUE name;
|
23
30
|
|
24
31
|
/* clear the default M_TBL already allocated for the new wrapper module */
|
25
32
|
st_free_table(RCLASS_M_TBL(class_mod_wrapper));
|
@@ -28,7 +35,12 @@ rb_prepend_module(VALUE klass, VALUE module)
|
|
28
35
|
RCLASS_M_TBL(class_mod_wrapper) = RCLASS_M_TBL(klass);
|
29
36
|
|
30
37
|
/* store name of current class in wrapper module for use by #to_s and #inspect */
|
31
|
-
|
38
|
+
if (NIL_P(rb_mod_name(klass)))
|
39
|
+
name = rb_str_new2("Anon");
|
40
|
+
else
|
41
|
+
name = rb_mod_name(klass);
|
42
|
+
|
43
|
+
rb_iv_set(class_mod_wrapper, "__class_name__", name);
|
32
44
|
|
33
45
|
/* set current class's #to_s to return ClassName* */
|
34
46
|
rb_define_singleton_method(klass, "to_s", klass_to_s, 0);
|
data/lib/prepend/version.rb
CHANGED
data/test/test.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
direc = File.dirname(__FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require "#{direc}/../lib/prepend"
|
4
|
+
require 'bacon'
|
5
|
+
|
6
|
+
describe 'prepend' do
|
7
|
+
before do
|
8
|
+
@m1 = Module.new {
|
9
|
+
def hello
|
10
|
+
:hello
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should make prepend a method on Module' do
|
16
|
+
Module.method_defined?(:prepend).should.equal true
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should make module methods have precedence over class instance methods' do
|
20
|
+
c = Class.new {
|
21
|
+
def hello
|
22
|
+
:bye
|
23
|
+
end
|
24
|
+
}
|
25
|
+
c.new.hello.should.equal :bye
|
26
|
+
c.send(:prepend, @m1)
|
27
|
+
c.new.hello.should.equal :hello
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should make module 1 instance methods have precedence over module 2 instance methods' do
|
31
|
+
m2 = Module.new {
|
32
|
+
def hello
|
33
|
+
:evil
|
34
|
+
end
|
35
|
+
}
|
36
|
+
m2.send(:prepend, @m1)
|
37
|
+
|
38
|
+
c = Class.new
|
39
|
+
c.send(:prepend, m2)
|
40
|
+
|
41
|
+
c.new.hello.should.equal :hello
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Mair (banisterfiend)
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-29 00:00:00 +13:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -35,7 +35,8 @@ files:
|
|
35
35
|
- ext/prepend/extconf.rb
|
36
36
|
- ext/prepend/compat.h
|
37
37
|
- ext/prepend/prepend.c
|
38
|
-
|
38
|
+
- test/test.rb
|
39
|
+
has_rdoc: true
|
39
40
|
homepage: http://banisterfiend.wordpress.com
|
40
41
|
licenses: []
|
41
42
|
|