womb 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -7
  3. data/lib/womb.rb +9 -5
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 210d82c5031506a430336295cce6651d36b5e45a
4
- data.tar.gz: 80342be41a52d99acd6778ad7b3cf53c067786ae
3
+ metadata.gz: d973d70e4c4c77d477490cea8c99b6974405f513
4
+ data.tar.gz: 14bcb775ea8c721f1c2b8a4fde9b218d356b37a2
5
5
  SHA512:
6
- metadata.gz: 4f993ada4bd2e423ef88c0908eccd1b5a806d2cea4a7c704f18d6c67e8cac286ca4097da279d150b113c8f0b1e025ab02971e0b4ae3e404a66731b58b0e782b0
7
- data.tar.gz: bc965594074750e3b27f2bb7341b591a853b230f478e45f3350ff3d3058218fa24bc54d0c2225378355572abcd70caaa12a881d117b409b2b47c0f523e268d79
6
+ metadata.gz: f9d2a4c0fc3e2cf8b8beea28fe96f13766abcc9604e336b95af0f80367963a2875d6c0b1833331d55f7ec6d058b0c5996e47663624986469925ae84096e73c54
7
+ data.tar.gz: 93974489fe099aeb6c4727dbfc33756e895d28d41d5fd8ac9976337d306131ed882b079874ac9d80085b876be9807890bcbddfce54200727d0cea8e610c81481
data/README.md CHANGED
@@ -6,11 +6,9 @@ reduce boiler plate.
6
6
 
7
7
  ## Usage
8
8
 
9
- Once wrapped around an object, `Womb` forwards messages via `method_missing` to
10
- the object. All forwarded messages are sent with the `send` method, such that
11
- normally private methods such as `attr_accessor` and `define_method` can be
12
- used. After the object has been defined, the `birth` method returns the
13
- object.
9
+ Once wrapped around an object, `Womb` stores all messages via `method_missing`
10
+ and then sends them to the object when the `birth` method is called, returning
11
+ the defined object.
14
12
 
15
13
  ``` ruby
16
14
  require 'womb'
@@ -33,7 +31,7 @@ an `initialize` method that simply sets instance variables from it's arguments.
33
31
 
34
32
  ``` ruby
35
33
  RegPolygon = Womb[Module.new]
36
- .assign(:angle) { |sides| (sides - 2) * Math::PI / sides }
34
+ .assign(:interior_angle) { |sides| (sides - 2) * Math::PI / sides }
37
35
  .birth
38
36
 
39
37
  Triangle = Womb[Module.new]
@@ -42,7 +40,7 @@ Triangle = Womb[Module.new]
42
40
 
43
41
  RegTriangle = Womb[Class.new]
44
42
  .init(:base)
45
- .def(:height) { @base * Math.sin(RegPolygon.angle(3)) }
43
+ .def(:height) { @base * Math.sin(RegPolygon.interior_angle(3)) }
46
44
  .def(:area) { Triangle.area(@base, height) }
47
45
  .birth
48
46
 
@@ -5,10 +5,13 @@ class Womb < BasicObject
5
5
 
6
6
  def initialize(obj)
7
7
  @obj = obj
8
+ @messages = []
8
9
  end
9
10
 
10
- def method_missing(name, *args, &b)
11
- obj.send(aliases[name] || name, *args, &b)
11
+ def method_missing(method, *args, &b)
12
+ method = aliases[method] || method
13
+ return super unless obj.respond_to?(method, true)
14
+ @messages << [obj, [method, *args], b]
12
15
  self
13
16
  end
14
17
 
@@ -20,12 +23,14 @@ class Womb < BasicObject
20
23
  end
21
24
  end
22
25
 
23
- def send_to_singleton(*args)
24
- obj.singleton_class.send(*args)
26
+ def send_to_singleton(*args, &b)
27
+ @messages << [obj.singleton_class, args, b]
25
28
  self
26
29
  end
27
30
 
28
31
  def birth
32
+ messages = @messages
33
+ @obj.class_eval { messages.each { |(target, args, b)| target.send(*args, &b) } }
29
34
  @obj
30
35
  end
31
36
 
@@ -37,5 +42,4 @@ class Womb < BasicObject
37
42
  @aliases ||= { assign: :define_singleton_method,
38
43
  def: :define_method }
39
44
  end
40
-
41
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: womb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max White