rebinder 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 (3) hide show
  1. data/lib/rebinder.rb +72 -24
  2. data/lib/rebinder/version.rb +1 -1
  3. metadata +1 -1
@@ -2,26 +2,56 @@
2
2
 
3
3
  class Method
4
4
  def rebind(*args,&block)
5
- unbind.bind(*args,&block)
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.bind(obj).call }
18
+ proc { |obj| self.✈(obj).◊ }
13
19
  end
14
20
 
21
+ alias ✈ bind
22
+ alias ⇧ owner
23
+
15
24
  def apply(obj)
16
- bind(obj).call
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
- # id = Object.☃.object_id
45
- # #=> #<UnboundMethod: Object(Kernel)#object_id>
46
- #
47
- # [:omg, :wtf, :lol].map(&id)
48
- # #=> [507368, 507528, 507688]
49
- #
50
- # id.☏ :lmao
51
- # #=> 507048
52
- #
53
- # add = 5.method(:+)
54
- #
55
- # [1,2,3].map(&add)
56
- # #=> [6,7,8]
57
- #
58
- # [1,2,3].map(&add.✈ 10)
59
- # #=> [11,12,13]
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
 
@@ -1,3 +1,3 @@
1
1
  module Rebinder
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rebinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: