rebinder 0.0.1 → 0.0.2
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.
- data/lib/rebinder.rb +60 -0
- data/lib/rebinder/version.rb +1 -1
- metadata +2 -2
- data/lib/rebind.rb +0 -5
data/lib/rebinder.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class Method
|
4
|
+
def rebind(*args,&block)
|
5
|
+
unbind.bind(*args,&block)
|
6
|
+
end
|
7
|
+
alias ✈ rebind
|
8
|
+
end
|
9
|
+
|
10
|
+
class UnboundMethod
|
11
|
+
def to_proc
|
12
|
+
proc { |obj| self.bind(obj).call }
|
13
|
+
end
|
14
|
+
|
15
|
+
def apply(obj)
|
16
|
+
bind(obj).call
|
17
|
+
end
|
18
|
+
alias ☏ apply
|
19
|
+
end
|
20
|
+
|
21
|
+
class Module
|
22
|
+
|
23
|
+
class BadIdeaProxy < BasicObject
|
24
|
+
|
25
|
+
def initialize(obj)
|
26
|
+
@obj = obj
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(s)
|
30
|
+
@obj.instance_method(s)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def snowman(arg=nil)
|
36
|
+
return instance_method(arg) if arg
|
37
|
+
BadIdeaProxy.new(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
alias ☃ snowman
|
41
|
+
|
42
|
+
end
|
43
|
+
|
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]
|
60
|
+
|
data/lib/rebinder/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -22,7 +22,7 @@ files:
|
|
22
22
|
- .gitignore
|
23
23
|
- Gemfile
|
24
24
|
- Rakefile
|
25
|
-
- lib/
|
25
|
+
- lib/rebinder.rb
|
26
26
|
- lib/rebinder/version.rb
|
27
27
|
- rebinder.gemspec
|
28
28
|
homepage: ''
|