ruby-nuggets 0.4.2 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Rakefile +1 -1
- data/lib/nuggets/file/which.rb +1 -1
- data/lib/nuggets/string/evaluate.rb +3 -1
- data/lib/nuggets/string/msub.rb +14 -3
- data/lib/nuggets/version.rb +1 -1
- metadata +2 -2
data/README
CHANGED
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ Hen.lay! {{
|
|
21
21
|
|
22
22
|
desc "Run all examples"
|
23
23
|
task :examples do
|
24
|
-
ruby =
|
24
|
+
ruby = Config::CONFIG.values_at('RUBY_INSTALL_NAME', 'EXEEXT').join
|
25
25
|
|
26
26
|
Dir['lib/nuggets/*/**/*.rb'].each { |file|
|
27
27
|
puts ">>>>> #{file} <<<<<"
|
data/lib/nuggets/file/which.rb
CHANGED
@@ -35,7 +35,7 @@ class String
|
|
35
35
|
# substitution expressions ("#{...}") that can get evaluated in a different
|
36
36
|
# environment (= +binding+) at a later point.
|
37
37
|
def evaluate(binding = TOPLEVEL_BINDING)
|
38
|
-
eval(%Q{
|
38
|
+
eval(%Q{%Q{#{self}}}, binding)
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
@@ -50,4 +50,6 @@ if $0 == __FILE__
|
|
50
50
|
end
|
51
51
|
|
52
52
|
p foo(s)
|
53
|
+
|
54
|
+
p 'a"b"c'.evaluate(binding)
|
53
55
|
end
|
data/lib/nuggets/string/msub.rb
CHANGED
@@ -52,6 +52,11 @@ class String
|
|
52
52
|
# Destructive version of #msub.
|
53
53
|
def msub!(*substitutions)
|
54
54
|
substitutions = substitutions.first if substitutions.first.is_a?(Hash)
|
55
|
+
|
56
|
+
binding = substitutions.is_a?(Hash) ? substitutions.delete(:__binding__) :
|
57
|
+
substitutions.last.is_a?(Hash) ? substitutions.pop[:__binding__] : nil
|
58
|
+
binding ||= Kernel.binding
|
59
|
+
|
55
60
|
keys, subs, cache = [], [], {}
|
56
61
|
|
57
62
|
substitutions.each { |key, value|
|
@@ -62,9 +67,7 @@ class String
|
|
62
67
|
}
|
63
68
|
|
64
69
|
gsub!(Regexp.union(*keys)) { |match|
|
65
|
-
cache[match] ||= subs.find { |key, _|
|
66
|
-
key =~ match
|
67
|
-
}.last.evaluate(binding)
|
70
|
+
cache[match] ||= subs.find { |key, _| key =~ match }.last.evaluate(binding)
|
68
71
|
}
|
69
72
|
end
|
70
73
|
|
@@ -79,4 +82,12 @@ if $0 == __FILE__
|
|
79
82
|
|
80
83
|
s.msub!('a' => 'o', 'o' => 'a')
|
81
84
|
p s
|
85
|
+
|
86
|
+
t = '!!!'
|
87
|
+
begin
|
88
|
+
p s.msub('r' => '???', 'z' => '#{t}')
|
89
|
+
rescue NameError => err
|
90
|
+
warn err
|
91
|
+
end
|
92
|
+
p s.msub('r' => '???', 'z' => '#{t}', :__binding__ => binding)
|
82
93
|
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.4.
|
4
|
+
version: 0.4.4
|
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: 2009-01-
|
12
|
+
date: 2009-01-26 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|