eigenclass 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +61 -0
- data/Rakefile +1 -1
- data/lib/eigenclass.rb +74 -76
- metadata +6 -6
- data/CHANGELOG +0 -6
- data/README.markdown +0 -55
data/README.rdoc
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= eigenclass
|
2
|
+
|
3
|
+
Utility methods for modifying a ruby object's eigenclass/metaclass
|
4
|
+
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
gem install eigenclass
|
9
|
+
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
This gem allows you to define class level accessors, readers, and writers
|
14
|
+
|
15
|
+
class SomeClass
|
16
|
+
eattr_accessor :test_accessor
|
17
|
+
eattr_reader :test_reader
|
18
|
+
eattr_writer :test_writer
|
19
|
+
end
|
20
|
+
|
21
|
+
SomeClass.test_accessor = 'testing'
|
22
|
+
|
23
|
+
You can also dynamically create class methods
|
24
|
+
|
25
|
+
SomeClass.class_eval do
|
26
|
+
define_class_method 'test_class_method' do
|
27
|
+
'test'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
SomeClass.test_class_method # returns 'test'
|
32
|
+
|
33
|
+
You can even evaluate a block of code inside the scope of an object's eigenclass
|
34
|
+
|
35
|
+
SomeClass.eigenclass_eval do
|
36
|
+
attr_accessor :test_eigenclass_eval
|
37
|
+
end
|
38
|
+
|
39
|
+
SomeClass.test_eigenclass_eval = true
|
40
|
+
|
41
|
+
|
42
|
+
A reference to any object's eigenclass can be accessed by calling
|
43
|
+
|
44
|
+
SomeObject.eigenclass
|
45
|
+
|
46
|
+
|
47
|
+
== Note on Patches/Pull Requests
|
48
|
+
|
49
|
+
* Fork the project.
|
50
|
+
* Make your feature addition or bug fix.
|
51
|
+
* Add tests for it. This is important so I don't break it in a
|
52
|
+
future version unintentionally.
|
53
|
+
* Commit, do not mess with rakefile, version, or history.
|
54
|
+
(if you want to have your own version, that is fine but
|
55
|
+
bump version in a commit by itself I can ignore when I pull)
|
56
|
+
* Send me a pull request. Bonus points for topic branches.
|
57
|
+
|
58
|
+
|
59
|
+
== Contact
|
60
|
+
|
61
|
+
Problems, comments, and suggestions all welcome: shuber@huberry.com
|
data/Rakefile
CHANGED
@@ -17,6 +17,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
17
17
|
rdoc.rdoc_dir = 'rdoc'
|
18
18
|
rdoc.title = 'Eigenclass'
|
19
19
|
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
-
rdoc.rdoc_files.include('README
|
20
|
+
rdoc.rdoc_files.include('README*')
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
22
|
end
|
data/lib/eigenclass.rb
CHANGED
@@ -1,79 +1,77 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
eigenclass.instance_eval &block
|
75
|
-
end
|
1
|
+
module Eigenclass
|
2
|
+
# Uses <tt>eigenclass_eval</tt> to define attr_accessors in an object's <tt>eigenclass</tt>
|
3
|
+
# which can be called like a class methods
|
4
|
+
#
|
5
|
+
# Example
|
6
|
+
#
|
7
|
+
# class User
|
8
|
+
# eattr_accessor :testing
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# User.testing = true
|
12
|
+
def eattr_accessor(*attrs)
|
13
|
+
eigenclass_eval { attr_accessor *attrs }
|
14
|
+
end
|
15
|
+
|
16
|
+
# Uses <tt>eigenclass_eval</tt> to define attr_readers in an object's <tt>eigenclass</tt>
|
17
|
+
# which can be called like a class methods
|
18
|
+
#
|
19
|
+
# Example
|
20
|
+
#
|
21
|
+
# class User
|
22
|
+
# eattr_reader :testing
|
23
|
+
# @testing = true
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# User.testing # returns true
|
27
|
+
def eattr_reader(*attrs)
|
28
|
+
eigenclass_eval { attr_reader *attrs }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Uses <tt>eigenclass_eval</tt> to define attr_writers in an object's <tt>eigenclass</tt>
|
32
|
+
# which can be called like a class methods
|
33
|
+
#
|
34
|
+
# Example
|
35
|
+
#
|
36
|
+
# class User
|
37
|
+
# eattr_writer :testing
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# User.testing = true
|
41
|
+
def eattr_writer(*attrs)
|
42
|
+
eigenclass_eval { attr_writer *attrs }
|
43
|
+
end
|
44
|
+
|
45
|
+
# Uses <tt>eigenclass_eval</tt> to define a method in an object's <tt>eigenclass</tt>
|
46
|
+
# which can be called like a class method
|
47
|
+
#
|
48
|
+
# Example
|
49
|
+
#
|
50
|
+
# User.class_eval do
|
51
|
+
# define_class_method 'testing' do
|
52
|
+
# 'test'
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# User.testing # returns 'test'
|
57
|
+
def define_class_method(name, &block)
|
58
|
+
eigenclass_eval { define_method name, &block }
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns an object's eigenclass
|
62
|
+
def eigenclass
|
63
|
+
class << self; self; end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Accepts a block to evaluate inside the scope of an object's <tt>eigenclass</tt>
|
67
|
+
#
|
68
|
+
# Example
|
69
|
+
#
|
70
|
+
# User.eigenclass_eval { attr_accessor :testing }
|
71
|
+
# User.testing = true
|
72
|
+
def eigenclass_eval(&block)
|
73
|
+
eigenclass.instance_eval &block
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
79
|
-
Object.send :include,
|
77
|
+
Object.send :include, Eigenclass
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eigenclass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-28 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,12 +22,12 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
- CHANGELOG
|
26
25
|
- lib/eigenclass.rb
|
27
26
|
- MIT-LICENSE
|
28
27
|
- Rakefile
|
29
|
-
- README.
|
30
|
-
|
28
|
+
- README.rdoc
|
29
|
+
- test/eigenclass_test.rb
|
30
|
+
has_rdoc: true
|
31
31
|
homepage: http://github.com/shuber/eigenclass
|
32
32
|
licenses: []
|
33
33
|
|
@@ -36,7 +36,7 @@ rdoc_options:
|
|
36
36
|
- --line-numbers
|
37
37
|
- --inline-source
|
38
38
|
- --main
|
39
|
-
- README.
|
39
|
+
- README.rdoc
|
40
40
|
require_paths:
|
41
41
|
- lib
|
42
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/CHANGELOG
DELETED
data/README.markdown
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
Eigenclass
|
2
|
-
==========
|
3
|
-
|
4
|
-
Utility methods for modifying a ruby object's eigenclass/metaclass
|
5
|
-
|
6
|
-
|
7
|
-
Installation
|
8
|
-
------------
|
9
|
-
|
10
|
-
gem install shuber-eigenclass --source http://gems.github.com
|
11
|
-
|
12
|
-
|
13
|
-
Usage
|
14
|
-
-----
|
15
|
-
|
16
|
-
This gem allows you to define class level accessors, readers, and writers
|
17
|
-
|
18
|
-
class SomeClass
|
19
|
-
eattr_accessor :test_accessor
|
20
|
-
eattr_reader :test_reader
|
21
|
-
eattr_writer :test_writer
|
22
|
-
end
|
23
|
-
|
24
|
-
SomeClass.test_accessor = 'testing'
|
25
|
-
|
26
|
-
|
27
|
-
You can also dynamically create class methods
|
28
|
-
|
29
|
-
SomeClass.class_eval do
|
30
|
-
define_class_method 'test_class_method' do
|
31
|
-
'test'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
SomeClass.test_class_method # returns 'test'
|
36
|
-
|
37
|
-
|
38
|
-
You can even evaluate a block of code inside the scope of an object's eigenclass
|
39
|
-
|
40
|
-
SomeClass.eigenclass_eval do
|
41
|
-
attr_accessor :test_eigenclass_eval
|
42
|
-
end
|
43
|
-
|
44
|
-
SomeClass.test_eigenclass_eval = true
|
45
|
-
|
46
|
-
|
47
|
-
A reference to any object's eigenclass can be accessed by calling
|
48
|
-
|
49
|
-
SomeObject.eigenclass
|
50
|
-
|
51
|
-
|
52
|
-
Contact
|
53
|
-
-------
|
54
|
-
|
55
|
-
Problems, comments, and suggestions all welcome: [shuber@huberry.com](mailto:shuber@huberry.com)
|