abstraction 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION.yml +1 -1
  2. data/lib/abstraction.rb +17 -27
  3. data/spec/spec.opts +1 -0
  4. metadata +2 -2
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -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 = self
5
+ @abstract_class = true
23
6
 
24
- raise_if_abstract = lambda do |*args, &block|
25
- if self == abstract_class
26
- raise AbstractClassError, "#{self} is an abstract class and cannot be instantiated"
27
- else
28
- super *args, &block
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
- end
31
-
32
- meta_def :new, &raise_if_abstract
33
- meta_def :allocate, &raise_if_abstract
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
@@ -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.2
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-04-12 00:00:00 -04:00
12
+ date: 2009-05-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15