ruby-nuggets 0.0.2.145 → 0.0.3.146
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/nuggets/proc/bind.rb +70 -0
- data/lib/nuggets/version.rb +1 -1
- metadata +8 -7
data/README
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
+
# language. #
|
6
|
+
# #
|
7
|
+
# Copyright (C) 2007-2008 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
+
# #
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
+
# any later version. #
|
16
|
+
# #
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
+
# more details. #
|
21
|
+
# #
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
+
# #
|
25
|
+
###############################################################################
|
26
|
+
#++
|
27
|
+
|
28
|
+
require File.join(File.dirname(__FILE__), '..', 'object', 'singleton_class')
|
29
|
+
|
30
|
+
class Proc
|
31
|
+
|
32
|
+
# call.seq:
|
33
|
+
# proc.bind(object) => aMethod
|
34
|
+
#
|
35
|
+
# Straight from Rails' ActiveSupport -- effectively binds _proc_ to +object+.
|
36
|
+
def bind(object)
|
37
|
+
block, time = self, Time.now
|
38
|
+
|
39
|
+
object.singleton_class.class_eval {
|
40
|
+
method_name = "__bind_#{time.to_i}_#{time.usec}"
|
41
|
+
define_method(method_name, &block)
|
42
|
+
|
43
|
+
method = instance_method(method_name)
|
44
|
+
remove_method(method_name)
|
45
|
+
|
46
|
+
method
|
47
|
+
}.bind(object)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
if $0 == __FILE__
|
53
|
+
l = lambda { bla }
|
54
|
+
|
55
|
+
begin
|
56
|
+
l.call
|
57
|
+
rescue NameError => err
|
58
|
+
puts "#{err} (#{err.class})"
|
59
|
+
end
|
60
|
+
|
61
|
+
module Bla # :nodoc:
|
62
|
+
|
63
|
+
def self.bla
|
64
|
+
puts 'blub'
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
l.bind(Bla).call
|
70
|
+
end
|
data/lib/nuggets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nuggets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3.146
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-01-
|
12
|
+
date: 2008-01-04 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/nuggets/string/word_wrap.rb
|
35
35
|
- lib/nuggets/string/nsub.rb
|
36
36
|
- lib/nuggets/hash/insert.rb
|
37
|
+
- lib/nuggets/proc/bind.rb
|
37
38
|
- lib/nuggets/array/rand.rb
|
38
39
|
- lib/nuggets/array/to_hash.rb
|
39
40
|
- lib/nuggets/array/flatten_once.rb
|
@@ -53,15 +54,15 @@ has_rdoc: true
|
|
53
54
|
homepage:
|
54
55
|
post_install_message:
|
55
56
|
rdoc_options:
|
56
|
-
- --title
|
57
|
-
- ruby-nuggets Application documentation
|
58
|
-
- --line-numbers
|
59
|
-
- --main
|
60
|
-
- README
|
61
57
|
- --inline-source
|
62
58
|
- --all
|
63
59
|
- --charset
|
64
60
|
- UTF-8
|
61
|
+
- --main
|
62
|
+
- README
|
63
|
+
- --title
|
64
|
+
- ruby-nuggets Application documentation
|
65
|
+
- --line-numbers
|
65
66
|
require_paths:
|
66
67
|
- lib
|
67
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|