real_include 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,12 +19,35 @@ class_alloc(VALUE flags, VALUE klass)
19
19
  }
20
20
  #endif
21
21
 
22
+
23
+ static VALUE
24
+ class_to_s(VALUE self)
25
+ {
26
+ VALUE attached = rb_iv_get(self, "__attached__");
27
+
28
+ if (attached)
29
+ return rb_mod_name(rb_iv_get(attached, "__module__"));
30
+ else
31
+ return rb_mod_name(rb_iv_get(self, "__module__"));
32
+ }
33
+
22
34
  static VALUE
23
35
  include_class_new(VALUE module, VALUE super)
24
36
  {
25
37
  /* base case for recursion */
26
38
  if (module == rb_singleton_class(rb_cModule))
27
39
  return module;
40
+
41
+ if (TYPE(module) == T_ICLASS) {
42
+
43
+ /* real_include */
44
+ if (rb_iv_get(module, "__module__"))
45
+ module = rb_iv_get(module, "__module__");
46
+
47
+ /* ordinary Module#include */
48
+ else
49
+ module = KLASS_OF(module);
50
+ }
28
51
 
29
52
  /* allocate iclass */
30
53
  #ifdef RUBY_19
@@ -40,6 +63,9 @@ include_class_new(VALUE module, VALUE super)
40
63
  RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
41
64
  RCLASS_SUPER(klass) = super;
42
65
 
66
+ if (TYPE(module) == T_MODULE || FL_TEST(module, FL_SINGLETON))
67
+ rb_iv_set(klass, "__module__", module);
68
+
43
69
  /* create IClass for module's singleton */
44
70
  /* if super is 0 then we're including into a module (not a class), so treat as special case */
45
71
  VALUE meta = include_class_new(KLASS_OF(module), super ? KLASS_OF(super) : rb_cModule);
@@ -51,7 +77,10 @@ include_class_new(VALUE module, VALUE super)
51
77
  FL_SET(meta, FL_SINGLETON);
52
78
 
53
79
  /* attach singleton to module */
54
- rb_singleton_class_attached((VALUE)meta, (VALUE)klass);
80
+ rb_iv_set(meta, "__attached__", klass);
81
+
82
+ /* attach the #to_s method to the metaclass (so #ancestors doesn't look weird) */
83
+ rb_define_singleton_method(meta, "to_s", class_to_s, 0);
55
84
  }
56
85
  /* assign the metaclass to module's klass */
57
86
  KLASS_OF(klass) = meta;
@@ -1,3 +1,3 @@
1
1
  module RealInclude
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: real_include
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 5
10
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
11
10
  platform: ruby
12
11
  authors:
13
12
  - John Mair (banisterfiend)
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-09 00:00:00 +13:00
17
+ date: 2010-10-12 00:00:00 +13:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -51,7 +50,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
- hash: 3
55
53
  segments:
56
54
  - 0
57
55
  version: "0"
@@ -60,7 +58,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
58
  requirements:
61
59
  - - ">="
62
60
  - !ruby/object:Gem::Version
63
- hash: 3
64
61
  segments:
65
62
  - 0
66
63
  version: "0"