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 CHANGED
@@ -1,2 +1,5 @@
1
- 10/10/210 version 0.1.0
1
+ 29/10/2010 version 0.1.5
2
+ * when module/class has no name set name to Anon rather than leave as nil,
3
+ as this may be causing segfault with rb_str_concat
4
+ 10/10/2010 version 0.1.0
2
5
  * release!
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
- # ["lib/1.9/real_include.so", "lib/1.8/real_include.so"] +
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|
@@ -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
- return rb_str_concat(rb_mod_name(self), rb_str_new2("*"));
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
- rb_iv_set(class_mod_wrapper, "__class_name__", rb_mod_name(klass));
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);
@@ -1,3 +1,3 @@
1
1
  module Prepend
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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
- - 0
9
- version: 0.1.0
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-10 00:00:00 +13:00
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
- has_rdoc: false
38
+ - test/test.rb
39
+ has_rdoc: true
39
40
  homepage: http://banisterfiend.wordpress.com
40
41
  licenses: []
41
42