singleton_from 0.1.0 → 0.2.0
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/README.md +7 -3
- data/lib/singleton_from/version.rb +1 -1
- data/lib/singleton_from.rb +10 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f37220ea9a1f2f37624e2de541a7c77b1bdf3e4
|
4
|
+
data.tar.gz: a858f2ed49f437635c954ea412bd31fb0343898e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38c2b90c846a78edc9c721da7d31944408e99c59e07cfe3dfe0281d8132441f58cca279146807837efbfa5c763f6699a1b0b50c94f5a158d049691d1b8ef0296
|
7
|
+
data.tar.gz: bb3c156c0d45062f837fc91a43ae5ae7914c24f5348ab8793fded0f626037f40e83a9eb3956ad1758b5caa3bb7c1c7d01ffa89c83d7dabd7cf6d2a0ce6595c7b
|
data/README.md
CHANGED
@@ -26,18 +26,22 @@ Or install it yourself as:
|
|
26
26
|
class A
|
27
27
|
singleton_from :start
|
28
28
|
|
29
|
-
def initialize(arg1, arg2)
|
29
|
+
def initialize(arg1, arg2, &block)
|
30
|
+
p block.call
|
30
31
|
p "Initialize"
|
31
32
|
p arg1
|
32
33
|
p arg2
|
33
34
|
end
|
34
35
|
|
35
|
-
def start
|
36
|
+
def start(&block)
|
36
37
|
p "start"
|
38
|
+
p block.call
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
A.start("1", "2")
|
42
|
+
A.start("1", "2") do
|
43
|
+
p "Hi, everyone... :-)"
|
44
|
+
end
|
41
45
|
```
|
42
46
|
|
43
47
|
## License
|
data/lib/singleton_from.rb
CHANGED
@@ -3,25 +3,29 @@ require "singleton_from/version"
|
|
3
3
|
# class A
|
4
4
|
# singleton_from :start
|
5
5
|
#
|
6
|
-
# def initialize(arg1, arg2)
|
6
|
+
# def initialize(arg1, arg2, &block)
|
7
|
+
# p block.call
|
7
8
|
# p "Initialize"
|
8
9
|
# p arg1
|
9
10
|
# p arg2
|
10
11
|
# end
|
11
12
|
#
|
12
|
-
# def start
|
13
|
+
# def start(&block)
|
14
|
+
# p block.call
|
13
15
|
# p "start"
|
14
16
|
# end
|
15
17
|
# end
|
16
18
|
#
|
17
|
-
# A.start("1", "2")
|
19
|
+
# A.start("1", "2") do
|
20
|
+
# puts "Hi, everyone... :-)"
|
21
|
+
# end
|
18
22
|
|
19
23
|
class Object
|
20
24
|
class << self
|
21
25
|
def singleton_from(method_name)
|
22
|
-
self.class.send(:define_method, method_name) do |*args|
|
23
|
-
instance = self.new(*args)
|
24
|
-
instance.send(__method__)
|
26
|
+
self.class.send(:define_method, method_name) do |*args, &block|
|
27
|
+
instance = self.new(*args, &block)
|
28
|
+
instance.send(__method__, &block)
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|