rebinder 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rebinder.rb +72 -24
- data/lib/rebinder/version.rb +1 -1
- metadata +1 -1
data/lib/rebinder.rb
CHANGED
@@ -2,26 +2,56 @@
|
|
2
2
|
|
3
3
|
class Method
|
4
4
|
def rebind(*args,&block)
|
5
|
-
unbind
|
5
|
+
unbind.✈(*args,&block)
|
6
6
|
end
|
7
7
|
alias ✈ rebind
|
8
|
+
alias ◊ call
|
9
|
+
alias ⇧ owner
|
8
10
|
end
|
9
11
|
|
12
|
+
class Proc
|
13
|
+
alias ◊ call
|
14
|
+
end
|
15
|
+
|
10
16
|
class UnboundMethod
|
11
17
|
def to_proc
|
12
|
-
proc { |obj| self
|
18
|
+
proc { |obj| self.✈(obj).◊ }
|
13
19
|
end
|
14
20
|
|
21
|
+
alias ✈ bind
|
22
|
+
alias ⇧ owner
|
23
|
+
|
15
24
|
def apply(obj)
|
16
|
-
|
25
|
+
✈(obj).◊
|
17
26
|
end
|
18
27
|
alias ☏ apply
|
28
|
+
|
29
|
+
def compose(meth2)
|
30
|
+
meth1 = self
|
31
|
+
meth1.⇧.send(:define_method, :__composition) {
|
32
|
+
meth2.✈(meth1.✈(self).◊).◊
|
33
|
+
}
|
34
|
+
ret = meth1.⇧.☃.__composition
|
35
|
+
meth1.⇧.send :remove_method, :__composition
|
36
|
+
ret
|
37
|
+
end
|
38
|
+
alias • compose
|
39
|
+
|
40
|
+
def partial_application(arg)
|
41
|
+
meth = self
|
42
|
+
meth.⇧.send(:define_method, :__curry) { |*args|
|
43
|
+
meth.✈(self).◊(arg, *args)
|
44
|
+
}
|
45
|
+
ret = meth.⇧.☃.__curry
|
46
|
+
meth.⇧.send :remove_method, :__curry
|
47
|
+
ret
|
48
|
+
end
|
49
|
+
alias ∂ partial_application
|
50
|
+
|
19
51
|
end
|
20
52
|
|
21
53
|
class Module
|
22
|
-
|
23
54
|
class BadIdeaProxy < BasicObject
|
24
|
-
|
25
55
|
def initialize(obj)
|
26
56
|
@obj = obj
|
27
57
|
end
|
@@ -29,32 +59,50 @@ class Module
|
|
29
59
|
def method_missing(s)
|
30
60
|
@obj.instance_method(s)
|
31
61
|
end
|
32
|
-
|
33
62
|
end
|
34
63
|
|
35
64
|
def snowman(arg=nil)
|
36
65
|
return instance_method(arg) if arg
|
37
66
|
BadIdeaProxy.new(self)
|
38
67
|
end
|
39
|
-
|
40
68
|
alias ☃ snowman
|
41
|
-
|
42
69
|
end
|
43
70
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# id
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
71
|
+
if __FILE__ == $0
|
72
|
+
require 'minitest/autorun'
|
73
|
+
class OmgTest < MiniTest::Unit::TestCase
|
74
|
+
|
75
|
+
def test_☃
|
76
|
+
id = Object.☃.object_id
|
77
|
+
assert_equal "#<UnboundMethod: Object(Kernel)#object_id>", id.inspect
|
78
|
+
assert_equal [3,5,7], [1,2,3].map(&id)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_☏
|
82
|
+
upcase = String.☃.upcase
|
83
|
+
assert_equal "ZOMFG", upcase.☏("zomfg")
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_•
|
87
|
+
upcase = String.☃.upcase
|
88
|
+
reverse = String.☃.reverse
|
89
|
+
reverse_upcase = reverse.•(upcase)
|
90
|
+
assert_equal "OMG", reverse_upcase.☏("gmo")
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_✈
|
94
|
+
add = 5.method(:+)
|
95
|
+
assert_equal [6,7,8], [1,2,3].map(&add)
|
96
|
+
assert_equal [11,12,13], [1,2,3].map(&add.✈(10))
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_∂
|
100
|
+
add = Fixnum.☃.+
|
101
|
+
add3 = add.∂(3)
|
102
|
+
assert_equal 7, add3.☏(4)
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
60
108
|
|
data/lib/rebinder/version.rb
CHANGED