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 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.markdown')
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 Huberry
2
- module Eigenclass
3
- # Uses <tt>eigenclass_eval</tt> to define attr_accessors in an object's <tt>eigenclass</tt>
4
- # which can be called like a class methods
5
- #
6
- # Example
7
- #
8
- # class User
9
- # eattr_accessor :testing
10
- # end
11
- #
12
- # User.testing = true
13
- def eattr_accessor(*attrs)
14
- eigenclass_eval { attr_accessor *attrs }
15
- end
16
-
17
- # Uses <tt>eigenclass_eval</tt> to define attr_readers in an object's <tt>eigenclass</tt>
18
- # which can be called like a class methods
19
- #
20
- # Example
21
- #
22
- # class User
23
- # eattr_reader :testing
24
- # @testing = true
25
- # end
26
- #
27
- # User.testing # returns true
28
- def eattr_reader(*attrs)
29
- eigenclass_eval { attr_reader *attrs }
30
- end
31
-
32
- # Uses <tt>eigenclass_eval</tt> to define attr_writers in an object's <tt>eigenclass</tt>
33
- # which can be called like a class methods
34
- #
35
- # Example
36
- #
37
- # class User
38
- # eattr_writer :testing
39
- # end
40
- #
41
- # User.testing = true
42
- def eattr_writer(*attrs)
43
- eigenclass_eval { attr_writer *attrs }
44
- end
45
-
46
- # Uses <tt>eigenclass_eval</tt> to define a method in an object's <tt>eigenclass</tt>
47
- # which can be called like a class method
48
- #
49
- # Example
50
- #
51
- # User.class_eval do
52
- # define_class_method 'testing' do
53
- # 'test'
54
- # end
55
- # end
56
- #
57
- # User.testing # returns 'test'
58
- def define_class_method(name, &block)
59
- eigenclass_eval { define_method name, &block }
60
- end
61
-
62
- # Returns an object's eigenclass
63
- def eigenclass
64
- class << self; self; end
65
- end
66
-
67
- # Accepts a block to evaluate inside the scope of an object's <tt>eigenclass</tt>
68
- #
69
- # Example
70
- #
71
- # User.eigenclass_eval { attr_accessor :testing }
72
- # User.testing = true
73
- def eigenclass_eval(&block)
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, Huberry::Eigenclass
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.1
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: 2009-01-07 00:00:00 -05:00
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.markdown
30
- has_rdoc: false
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.markdown
39
+ - README.rdoc
40
40
  require_paths:
41
41
  - lib
42
42
  required_ruby_version: !ruby/object:Gem::Requirement
data/CHANGELOG DELETED
@@ -1,6 +0,0 @@
1
- 2009-01-07 - Sean Huber (shuber@huberry.com)
2
- * Initial commit
3
- * Update README
4
- * Add gemspec
5
- * Update gemspec to force github to rebuild gem
6
- * Rename cattr_* methods to eattr_* to avoid confusion and conflict with ActiveSupport's version
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)