abstraction 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/abstraction.rb +17 -27
- data/spec/spec.opts +1 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/abstraction.rb
CHANGED
@@ -1,36 +1,26 @@
|
|
1
1
|
class AbstractClassError < StandardError; end
|
2
2
|
|
3
|
-
# metaid
|
4
|
-
class Object
|
5
|
-
# The hidden singleton lurks behind everyone
|
6
|
-
def metaclass; class << self; self; end; end
|
7
|
-
def meta_eval &blk; metaclass.instance_eval &blk; end
|
8
|
-
|
9
|
-
# Adds methods to a metaclass
|
10
|
-
def meta_def name, &blk
|
11
|
-
meta_eval { define_method name, &blk }
|
12
|
-
end
|
13
|
-
|
14
|
-
# Defines an instance method within a class
|
15
|
-
def class_def name, &blk
|
16
|
-
class_eval { define_method name, &blk }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
3
|
class Class
|
21
4
|
def abstract
|
22
|
-
abstract_class =
|
5
|
+
@abstract_class = true
|
23
6
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
7
|
+
self.extend Module.new {
|
8
|
+
def new(*args, &block)
|
9
|
+
if @abstract_class
|
10
|
+
raise AbstractClassError, "#{self} is an abstract class and cannot be instantiated"
|
11
|
+
else
|
12
|
+
super *args, &block
|
13
|
+
end
|
29
14
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
15
|
+
|
16
|
+
def allocate(*args, &block)
|
17
|
+
if @abstract_class
|
18
|
+
raise AbstractClassError, "#{self} is an abstract class and cannot be instantiated"
|
19
|
+
else
|
20
|
+
super *args, &block
|
21
|
+
end
|
22
|
+
end
|
23
|
+
}
|
34
24
|
|
35
25
|
nil
|
36
26
|
end
|
data/spec/spec.opts
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstraction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Jaros
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-30 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|