eigenclass 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +26 -5
- data/lib/eigenclass.rb +2 -0
- data/lib/eigenclass/version.rb +1 -1
- data/spec/eigenclass_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28aeb226955ee8be653bfe54654bfaba09ac50a0
|
4
|
+
data.tar.gz: 0a9bba1df21d8a1963ce2ff9f977a2a922e3b228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514da0791c5302694e4117596e2d1226459d80116cdd96ccae4796dc6c7ad8d4d32da85c71f2867205046f73d142db9f91ee5986d6affae4f9bac51ade530252
|
7
|
+
data.tar.gz: c17519c4b8daf8f9502ca0f83a839452d712815f3a37fce995c41067d08997c67ea8d65481802df8f672cdca6a2cb8c5b17348fa96ae632f478d975b8f16efa1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,8 +26,7 @@ gem install eigenclass
|
|
26
26
|
Everything in Ruby is an object, including classes.
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
|
30
|
-
end
|
29
|
+
SomeObject = Class.new
|
31
30
|
```
|
32
31
|
|
33
32
|
Every object has an `eigenclass`.
|
@@ -48,7 +47,7 @@ class Object
|
|
48
47
|
end
|
49
48
|
```
|
50
49
|
|
51
|
-
Evaluating code within
|
50
|
+
Evaluating code within an `eigenclass` lets us do some cool things like defining class level attributes.
|
52
51
|
|
53
52
|
```ruby
|
54
53
|
SomeObject.eigenclass_eval do
|
@@ -67,6 +66,8 @@ class SomeObject
|
|
67
66
|
eattr_reader :example_reader
|
68
67
|
eattr_writer :example_writer
|
69
68
|
|
69
|
+
ealias_method :new_example_accessor, :example_accessor
|
70
|
+
|
70
71
|
edefine_method(:example_class_method) do
|
71
72
|
1 + 1
|
72
73
|
end
|
@@ -75,6 +76,23 @@ end
|
|
75
76
|
SomeObject.example_class_method #=> 2
|
76
77
|
```
|
77
78
|
|
79
|
+
When we `extend` modules, we're actually just calling `include` on an object's `eigenclass`.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
SomeObject.eigenclass.included_modules #=> [Eigenclass, Kernel]
|
83
|
+
|
84
|
+
Example = Module.new
|
85
|
+
SomeObject.extend(Example)
|
86
|
+
|
87
|
+
SomeObject.eigenclass.included_modules #=> [Example, Eigenclass, Kernel]
|
88
|
+
```
|
89
|
+
|
90
|
+
A convenience method for viewing an object's extended modules is available for us as well.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
SomeObject.extended_modules #=> [Example, Eigenclass, Kernel]
|
94
|
+
```
|
95
|
+
|
78
96
|
Since all objects have an `eigenclass`, we can even define methods for a single _instance_ of a class.
|
79
97
|
|
80
98
|
```ruby
|
@@ -87,15 +105,17 @@ other_object = SomeObject.new
|
|
87
105
|
other_object.example #=> NoMethodError undefined method `example' for #<SomeObject:0x007fee348dde00>
|
88
106
|
```
|
89
107
|
|
90
|
-
This is pretty incredible! We can hook in and inject behavior into any and all objects - **at runtime**!
|
108
|
+
This is pretty incredible! We can hook in and inject behavior into *any and all* objects - **at runtime**!
|
91
109
|
|
92
110
|
Ruby is like one big plugin framework - with an awesome standard library and amazing community!
|
93
111
|
|
94
|
-
|
95
112
|
## API
|
96
113
|
|
97
114
|
[YARD Documentation](http://www.rubydoc.info/github/shuber/eigenclass/master)
|
98
115
|
|
116
|
+
All methods defined by this gem are simple delegators to existing methods on the `eigenclass` object. The links below redirect to each corresponding method in the standard library documentation.
|
117
|
+
|
118
|
+
* [ealias_method](http://ruby-doc.org/core-1.9.3/Module.html#method-i-alias_method)
|
99
119
|
* [eattr_accessor](http://ruby-doc.org/core-1.9.3/Module.html#method-i-attr_accessor)
|
100
120
|
* [eattr_reader](http://ruby-doc.org/core-1.9.3/Module.html#method-i-attr_reader)
|
101
121
|
* [eattr_writer](http://ruby-doc.org/core-1.9.3/Module.html#method-i-attr_writer)
|
@@ -103,6 +123,7 @@ Ruby is like one big plugin framework - with an awesome standard library and ama
|
|
103
123
|
* [eigenclass](http://ruby-doc.org/core-1.9.2/Object.html#method-i-singleton_class)
|
104
124
|
* [eigenclass_eval](http://ruby-doc.org/core-1.9.3/BasicObject.html#method-i-instance_eval)
|
105
125
|
* [eigenclass_exec](http://ruby-doc.org/core-1.9.3/BasicObject.html#method-i-instance_exec)
|
126
|
+
* [extended_modules](http://ruby-doc.org/core-1.9.3/Module.html#method-i-included_modules)
|
106
127
|
|
107
128
|
|
108
129
|
## Testing
|
data/lib/eigenclass.rb
CHANGED
@@ -6,10 +6,12 @@ require 'eigenclass/version'
|
|
6
6
|
module Eigenclass
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
+
def_delegator :eigenclass, :alias_method, :ealias_method
|
9
10
|
def_delegator :eigenclass, :attr_accessor, :eattr_accessor
|
10
11
|
def_delegator :eigenclass, :attr_reader, :eattr_reader
|
11
12
|
def_delegator :eigenclass, :attr_writer, :eattr_writer
|
12
13
|
def_delegator :eigenclass, :define_method, :edefine_method
|
14
|
+
def_delegator :eigenclass, :included_modules, :extended_modules
|
13
15
|
def_delegator :eigenclass, :instance_eval, :eigenclass_eval
|
14
16
|
def_delegator :eigenclass, :instance_exec, :eigenclass_exec
|
15
17
|
|
data/lib/eigenclass/version.rb
CHANGED
data/spec/eigenclass_spec.rb
CHANGED
@@ -3,6 +3,10 @@ require_relative '../lib/eigenclass'
|
|
3
3
|
RSpec.describe Eigenclass do
|
4
4
|
subject { Object.new.extend(described_class) }
|
5
5
|
|
6
|
+
it { should delegate_method(:ealias_method)
|
7
|
+
.to(:eigenclass)
|
8
|
+
.as(:alias_method) }
|
9
|
+
|
6
10
|
it { should delegate_method(:eattr_accessor)
|
7
11
|
.to(:eigenclass)
|
8
12
|
.as(:attr_accessor) }
|
@@ -19,6 +23,10 @@ RSpec.describe Eigenclass do
|
|
19
23
|
.to(:eigenclass)
|
20
24
|
.as(:define_method) }
|
21
25
|
|
26
|
+
it { should delegate_method(:extended_modules)
|
27
|
+
.to(:eigenclass)
|
28
|
+
.as(:included_modules) }
|
29
|
+
|
22
30
|
describe '#eigenclass' do
|
23
31
|
it 'should return the eigenclass instance' do
|
24
32
|
expected = class << subject; self end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eigenclass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|