coderrr-mixico 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +6 -0
- data/lib/mixico.rb +69 -0
- data/test/mixico_test.rb +35 -0
- metadata +64 -0
data/README.markdown
ADDED
data/lib/mixico.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'inline'
|
3
|
+
|
4
|
+
class Module
|
5
|
+
inline do |builder|
|
6
|
+
builder.c %q{
|
7
|
+
static VALUE disable_mixin(VALUE super)
|
8
|
+
{
|
9
|
+
VALUE p, kid;
|
10
|
+
VALUE module = self;
|
11
|
+
|
12
|
+
Check_Type(super, T_MODULE);
|
13
|
+
for (kid = module, p = RCLASS(module)->super; p; kid = p, p = RCLASS(p)->super) {
|
14
|
+
if (BUILTIN_TYPE(p) == T_ICLASS) {
|
15
|
+
if (RBASIC(p)->klass == super) {
|
16
|
+
RCLASS(kid)->super = RCLASS(p)->super;
|
17
|
+
rb_clear_cache();
|
18
|
+
return p;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
return Qnil;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
builder.c %q{
|
28
|
+
static VALUE enable_mixin(VALUE mixin)
|
29
|
+
{
|
30
|
+
VALUE p;
|
31
|
+
VALUE module = self;
|
32
|
+
|
33
|
+
Check_Type(mixin, T_ICLASS);
|
34
|
+
Check_Type(RBASIC(mixin)->klass, T_MODULE);
|
35
|
+
for (p = module; p; p = RCLASS(p)->super) {
|
36
|
+
if (RCLASS(p)->super == RCLASS(mixin)->super) {
|
37
|
+
RCLASS(p)->super = mixin;
|
38
|
+
return RBASIC(mixin)->klass;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
return Qnil;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Proc
|
49
|
+
def mixin mod
|
50
|
+
eval('self', binding).extend mod
|
51
|
+
end
|
52
|
+
|
53
|
+
def mixout mod
|
54
|
+
(class << eval('self', binding); self end).disable_mixin mod
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Module
|
59
|
+
def mix_eval mod, *args, &blk
|
60
|
+
blk.mixin mod
|
61
|
+
begin
|
62
|
+
yield *args
|
63
|
+
ensure
|
64
|
+
blk.mixout mod
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
alias_method :mix_exec, :mix_eval
|
69
|
+
end
|
data/test/mixico_test.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/../lib/mixico"
|
4
|
+
|
5
|
+
class MixicoTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@p = Proc.new do
|
8
|
+
mixed_method
|
9
|
+
end
|
10
|
+
|
11
|
+
@m = Module.new do
|
12
|
+
def mixed_method
|
13
|
+
:im_mixed
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_mixin
|
19
|
+
@p.mixin @m
|
20
|
+
assert_equal :im_mixed, @p.call
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_mixout
|
24
|
+
@p.mixin @m
|
25
|
+
@p.mixout @m
|
26
|
+
assert_raises(NameError) { @p.call }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_mixout_after_call
|
30
|
+
@p.mixin @m
|
31
|
+
@p.call
|
32
|
+
@p.mixout @m
|
33
|
+
assert_raises(NameError) { @p.call }
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coderrr-mixico
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- coderrr
|
8
|
+
- why
|
9
|
+
autorequire: mixico
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-10-09 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: RubyInline
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.6.7
|
24
|
+
version:
|
25
|
+
description: see http://github.com/why/mixico
|
26
|
+
email: coderrr.contact@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- README.markdown
|
35
|
+
- mixico.gemspec
|
36
|
+
- lib/mixico.rb
|
37
|
+
has_rdoc: false
|
38
|
+
homepage: http://github.com/coderrr/mixico
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.2.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: 1.8.6 compatible version of why's mixico
|
63
|
+
test_files:
|
64
|
+
- test/mixico_test.rb
|