metaclass 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/README.md +6 -0
- data/Rakefile +11 -0
- data/lib/metaclass.rb +5 -0
- data/lib/metaclass/object_methods.rb +11 -0
- data/lib/metaclass/version.rb +3 -0
- data/metaclass.gemspec +19 -0
- data/test/object_methods_test.rb +31 -0
- data/test/test_helper.rb +5 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
Adds a `__metaclass__` method to all Ruby objects.
|
2
|
+
|
3
|
+
Motivations :-
|
4
|
+
|
5
|
+
* Even though WhyTheLuckyStiff's [metaid gem](https://rubygems.org/gems/metaid) does something similar, apparently the metaclass method without underscores [doesn't play well with Rails v2.3](https://github.com/floehopper/mocha/commit/f0749d6d291164cc9280aa8ba16f33d652d45fe1#commitcomment-475799).
|
6
|
+
* I'm trying to extract code out of the [mocha gem](https://github.com/floehopper/mocha) and this is an obvious candidate.
|
data/Rakefile
ADDED
data/lib/metaclass.rb
ADDED
data/metaclass.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "metaclass/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "metaclass"
|
7
|
+
s.version = Metaclass::VERSION
|
8
|
+
s.authors = ["James Mead"]
|
9
|
+
s.email = ["james@floehopper.org"]
|
10
|
+
s.homepage = "http://github.com/floehopper/metaclass"
|
11
|
+
s.summary = %q{Adds a metaclass method to all Ruby objects}
|
12
|
+
|
13
|
+
s.rubyforge_project = "metaclass"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ObjectMethodsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@klass = Class.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_define_method_on_only_one_instance_of_a_class
|
10
|
+
instance = @klass.new
|
11
|
+
assert_raises(NoMethodError) { instance.success? }
|
12
|
+
|
13
|
+
instance.__metaclass__.class_eval { def success?; true; end }
|
14
|
+
assert_nothing_raised(NoMethodError) { assert instance.success? }
|
15
|
+
|
16
|
+
another_instance = @klass.new
|
17
|
+
assert_raises(NoMethodError) { another_instance.success? }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_metaclass_ancestors
|
21
|
+
instance = @klass.new
|
22
|
+
assert instance.__metaclass__.ancestors.include?(Object)
|
23
|
+
assert instance.__metaclass__.ancestors.include?(Kernel)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_metaclass_is_itself_a_class
|
27
|
+
instance = @klass.new
|
28
|
+
assert instance.__metaclass__.is_a?(Class)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metaclass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- James Mead
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-11 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email:
|
24
|
+
- james@floehopper.org
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/metaclass.rb
|
37
|
+
- lib/metaclass/object_methods.rb
|
38
|
+
- lib/metaclass/version.rb
|
39
|
+
- metaclass.gemspec
|
40
|
+
- test/object_methods_test.rb
|
41
|
+
- test/test_helper.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/floehopper/metaclass
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project: metaclass
|
72
|
+
rubygems_version: 1.6.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Adds a metaclass method to all Ruby objects
|
76
|
+
test_files:
|
77
|
+
- test/object_methods_test.rb
|
78
|
+
- test/test_helper.rb
|