real_include 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,2 @@
1
- 4/10/10 version 0.1.0
2
- * release! This is still beta, not 100% tested yet..but appears to work OK so far
1
+ 4/10/10 version 0.1.0
2
+ * release! This is still beta, not 100% tested yet..but appears to work OK so far
data/README.markdown CHANGED
@@ -1,34 +1,36 @@
1
- Real Include
2
- --------------
3
-
4
- (c) John Mair (banisterfiend)
5
- MIT license
6
-
7
- Removes the shackles from Module#include - use Module#real_include to
8
- bring in singleton classes from modules. No more ugly ClassMethods and
9
- included() hook hacks.
10
-
11
- example:
12
-
13
- module M
14
- # class method
15
- def self.hello
16
- puts "hello!"
17
- end
18
-
19
- # instance method
20
- def bye
21
- puts "bye!"
22
- end
23
- end
24
-
25
- class A
26
- real_include M
27
- end
28
-
29
- # invoke class method
30
- A.hello #=> hello!
31
-
32
- # invoke instance method
33
- A.new.bye #=> bye!
34
-
1
+ Real Include
2
+ --------------
3
+
4
+ (c) John Mair (banisterfiend)
5
+ MIT license
6
+
7
+ ** Currently supports Ruby 1.9 only **
8
+
9
+ Removes the shackles from Module#include - use Module#real_include to
10
+ bring in singleton classes from modules. No more ugly ClassMethods and
11
+ included() hook hacks.
12
+
13
+ example:
14
+
15
+ module M
16
+ # class method
17
+ def self.hello
18
+ puts "hello!"
19
+ end
20
+
21
+ # instance method
22
+ def bye
23
+ puts "bye!"
24
+ end
25
+ end
26
+
27
+ class A
28
+ real_include M
29
+ end
30
+
31
+ # invoke class method
32
+ A.hello #=> hello!
33
+
34
+ # invoke instance method
35
+ A.new.bye #=> bye!
36
+
data/Rakefile CHANGED
@@ -1,36 +1,37 @@
1
- $LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..')
2
-
3
- require 'rake/clean'
4
- require 'rake/gempackagetask'
5
-
6
- # get the texplay version
7
- require 'lib/real_include/version'
8
-
9
- $dlext = Config::CONFIG['DLEXT']
10
-
11
- CLEAN.include("ext/**/*.#{$dlext}", "ext/**/*.log", "ext/**/*.o", "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "ext/**/*.def", "ext/**/*.pdb")
12
- CLOBBER.include("**/*.#{$dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
13
-
14
- specification = Gem::Specification.new do |s|
15
- s.name = "real_include"
16
- s.summary = "Fixing the limitation in traditional Module#include"
17
- s.version = RealInclude::VERSION
18
- s.date = Time.now.strftime '%Y-%m-%d'
19
- s.author = "John Mair (banisterfiend)"
20
- s.email = 'jrmair@gmail.com'
21
- s.description = s.summary
22
- s.require_path = 'lib'
23
- s.platform = Gem::Platform::RUBY
24
- s.homepage = "http://banisterfiend.wordpress.com"
25
- s.has_rdoc = false
26
-
27
- s.extensions = ["ext/real_include/extconf.rb"]
28
- s.files = ["Rakefile", "README.markdown", "CHANGELOG",
29
- "lib/real_include.rb", "lib/real_include/version.rb"] +
30
- FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
31
- end
32
-
33
- Rake::GemPackageTask.new(specification) do |package|
34
- package.need_zip = false
35
- package.need_tar = false
36
- end
1
+ $LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..')
2
+
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+
6
+ # get the texplay version
7
+ require 'lib/real_include/version'
8
+
9
+ $dlext = Config::CONFIG['DLEXT']
10
+
11
+ CLEAN.include("ext/**/*.#{$dlext}", "ext/**/*.log", "ext/**/*.o", "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "ext/**/*.def", "ext/**/*.pdb")
12
+ CLOBBER.include("**/*.#{$dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
13
+
14
+ specification = Gem::Specification.new do |s|
15
+ s.name = "real_include"
16
+ s.summary = "Fixing the limitation in traditional Module#include"
17
+ s.version = RealInclude::VERSION
18
+ s.date = Time.now.strftime '%Y-%m-%d'
19
+ s.author = "John Mair (banisterfiend)"
20
+ s.email = 'jrmair@gmail.com'
21
+ s.description = s.summary
22
+ s.require_path = 'lib'
23
+ s.platform = Gem::Platform::RUBY
24
+ #s.platform = 'i386-mingw32'
25
+ s.homepage = "http://banisterfiend.wordpress.com"
26
+ s.has_rdoc = false
27
+
28
+ s.extensions = ["ext/real_include/extconf.rb"]
29
+ s.files = ["Rakefile", "README.markdown", "CHANGELOG",
30
+ "lib/_real_include.rb", "lib/real_include/version.rb"]
31
+ FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
32
+ end
33
+
34
+ Rake::GemPackageTask.new(specification) do |package|
35
+ package.need_zip = false
36
+ package.need_tar = false
37
+ end
@@ -1,9 +1,9 @@
1
- require 'mkmf'
2
-
3
- # 1.9 compatibility
4
- $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/
5
-
6
- # let's use c99
7
- $CFLAGS += " -std=c99"
8
-
9
- create_makefile('real_include')
1
+ require 'mkmf'
2
+
3
+ # 1.9 compatibility
4
+ $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/
5
+
6
+ # let's use c99
7
+ $CFLAGS += " -std=c99"
8
+
9
+ create_makefile('real_include')
@@ -1,14 +1,14 @@
1
- # bring in user-defined extensions to TexPlay
2
- direc = File.dirname(__FILE__)
3
- dlext = Config::CONFIG['DLEXT']
4
- begin
5
- if RUBY_VERSION && RUBY_VERSION =~ /1.9/
6
- require "#{direc}/1.9/real_include.#{dlext}"
7
- else
8
- require "#{direc}/1.8/real_include.#{dlext}"
9
- end
10
- rescue LoadError => e
11
- require "#{direc}/real_include.#{dlext}"
12
- end
13
-
14
- require "#{direc}/real_include/version"
1
+ # bring in user-defined extensions to TexPlay
2
+ direc = File.dirname(__FILE__)
3
+ dlext = Config::CONFIG['DLEXT']
4
+ begin
5
+ if RUBY_VERSION && RUBY_VERSION =~ /1.9/
6
+ require "#{direc}/1.9/real_include.#{dlext}"
7
+ else
8
+ require "#{direc}/1.8/real_include.#{dlext}"
9
+ end
10
+ rescue LoadError => e
11
+ require "#{direc}/real_include.#{dlext}"
12
+ end
13
+
14
+ require "#{direc}/real_include/version"
@@ -1,3 +1,3 @@
1
- module RealInclude
2
- VERSION = "0.1.0"
3
- end
1
+ module RealInclude
2
+ VERSION = "0.1.1"
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: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 0
10
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - John Mair (banisterfiend)
@@ -31,12 +30,10 @@ files:
31
30
  - Rakefile
32
31
  - README.markdown
33
32
  - CHANGELOG
34
- - lib/real_include.rb
33
+ - lib/_real_include.rb
35
34
  - lib/real_include/version.rb
36
35
  - ext/real_include/extconf.rb
37
- - ext/real_include/compat.h
38
- - ext/real_include/real_include.c
39
- has_rdoc: true
36
+ has_rdoc: false
40
37
  homepage: http://banisterfiend.wordpress.com
41
38
  licenses: []
42
39
 
@@ -50,7 +47,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
47
  requirements:
51
48
  - - ">="
52
49
  - !ruby/object:Gem::Version
53
- hash: 3
54
50
  segments:
55
51
  - 0
56
52
  version: "0"
@@ -59,7 +55,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
55
  requirements:
60
56
  - - ">="
61
57
  - !ruby/object:Gem::Version
62
- hash: 3
63
58
  segments:
64
59
  - 0
65
60
  version: "0"
@@ -1,18 +0,0 @@
1
- /* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
2
-
3
- #ifndef GUARD_COMPAT_H
4
- #define GUARD_COMPAT_H
5
-
6
- #include <ruby.h>
7
-
8
- /* macros for backwards compatibility with 1.8 */
9
- #ifndef RUBY_19
10
- # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
11
- # define RCLASS_SUPER(c) (RCLASS(c)->super)
12
- # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
13
- #endif
14
-
15
- /* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
16
- #define KLASS_OF(c) (RBASIC(c)->klass)
17
-
18
- #endif
@@ -1,124 +0,0 @@
1
- #include "compat.h"
2
- #include "ruby.h"
3
-
4
- #define FALSE 0
5
- #define TRUE 1
6
-
7
- static VALUE
8
- class_alloc(VALUE flags, VALUE klass)
9
- {
10
- rb_classext_t *ext = ALLOC(rb_classext_t);
11
- NEWOBJ(obj, struct RClass);
12
- OBJSETUP(obj, klass, flags);
13
- obj->ptr = ext;
14
- RCLASS_IV_TBL(obj) = 0;
15
- RCLASS_M_TBL(obj) = 0;
16
- RCLASS_SUPER(obj) = 0;
17
- RCLASS_IV_INDEX_TBL(obj) = 0;
18
- return (VALUE)obj;
19
- }
20
-
21
- static VALUE
22
- include_class_new(VALUE module, VALUE super)
23
- {
24
- if (module == rb_singleton_class(rb_cModule))
25
- return module;
26
-
27
- VALUE klass = class_alloc(T_ICLASS, rb_singleton_class(rb_cModule));
28
-
29
- /* if (BUILTIN_TYPE(module) == T_ICLASS) { */
30
- /* module = RBASIC(module)->klass; */
31
- /* } */
32
- if (!RCLASS_IV_TBL(module)) {
33
- RCLASS_IV_TBL(module) = st_init_numtable();
34
- }
35
- RCLASS_IV_TBL(klass) = st_init_numtable();
36
- RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
37
- RCLASS_SUPER(klass) = super;
38
- /*
39
- if (TYPE(module) == T_ICLASS) {
40
- RBASIC(klass)->klass = RBASIC(module)->klass;
41
- }
42
- */
43
-
44
- /* create IClass for module's singleton */
45
-
46
- VALUE meta = include_class_new(KLASS_OF(module), super ? KLASS_OF(super) : rb_cModule);
47
- if (meta != rb_singleton_class(rb_cModule)) {
48
- FL_SET(meta, FL_SINGLETON);
49
-
50
- /* attach singleton to module */
51
- rb_singleton_class_attached(meta, klass);
52
- }
53
- /* assign the metaclass to module's klass */
54
- KLASS_OF(klass) = meta;
55
-
56
- OBJ_INFECT(klass, module);
57
- OBJ_INFECT(klass, super);
58
-
59
- return (VALUE)klass;
60
- }
61
-
62
- VALUE
63
- rb_real_include_module(VALUE klass, VALUE module)
64
- {
65
- VALUE p, c;
66
- int changed = 0;
67
-
68
- rb_frozen_class_p(klass);
69
- if (!OBJ_UNTRUSTED(klass)) {
70
- rb_secure(4);
71
- }
72
-
73
- if (TYPE(module) != T_MODULE) {
74
- Check_Type(module, T_MODULE);
75
- }
76
-
77
- OBJ_INFECT(klass, module);
78
- c = klass;
79
-
80
- /* ensure singleton class exists */
81
- rb_singleton_class(module);
82
- rb_singleton_class(klass);
83
-
84
- while (module) {
85
- int superclass_seen = FALSE;
86
-
87
- if (RCLASS_M_TBL(klass) == RCLASS_M_TBL(module))
88
- rb_raise(rb_eArgError, "cyclic include detected");
89
- /* ignore if the module included already in superclasses */
90
- for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
91
- switch (BUILTIN_TYPE(p)) {
92
- case T_ICLASS:
93
- if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
94
- if (!superclass_seen) {
95
- c = p; /* move insertion point */
96
- }
97
- goto skip;
98
- }
99
- break;
100
- case T_CLASS:
101
- superclass_seen = TRUE;
102
- break;
103
- }
104
- }
105
-
106
- VALUE imod = include_class_new(module, RCLASS_SUPER(c));
107
- RCLASS_SUPER(c) = imod;
108
- RCLASS_SUPER(KLASS_OF(c)) = KLASS_OF(imod);
109
- c = imod;
110
-
111
- if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
112
- changed = 1;
113
- skip:
114
- module = RCLASS_SUPER(module);
115
- }
116
- if (changed) rb_clear_cache();
117
-
118
- return Qnil;
119
- }
120
-
121
- void
122
- Init_real_include() {
123
- rb_define_method(rb_cModule, "real_include", rb_real_include_module, 1);
124
- }