epitools 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +16 -0
- data/VERSION +1 -1
- data/epitools.gemspec +13 -6
- data/lib/epitools.rb +48 -6
- data/lib/epitools/autoloads.rb +14 -3
- data/lib/epitools/browser.rb +8 -1
- data/lib/epitools/core_ext.rb +207 -0
- data/lib/epitools/core_ext/array.rb +98 -0
- data/lib/epitools/core_ext/enumerable.rb +306 -0
- data/lib/epitools/core_ext/hash.rb +201 -0
- data/lib/epitools/core_ext/numbers.rb +254 -0
- data/lib/epitools/core_ext/object.rb +195 -0
- data/lib/epitools/core_ext/string.rb +338 -0
- data/lib/epitools/core_ext/truthiness.rb +64 -0
- data/lib/epitools/iter.rb +22 -8
- data/lib/epitools/mimemagic.rb +0 -1
- data/lib/epitools/path.rb +149 -36
- data/lib/epitools/rash.rb +49 -37
- data/lib/epitools/term.rb +5 -1
- data/spec/{basetypes_spec.rb → core_ext_spec.rb} +190 -37
- data/spec/iter_spec.rb +9 -27
- data/spec/path_spec.rb +104 -46
- data/spec/permutations_spec.rb +3 -2
- data/spec/rash_spec.rb +21 -7
- data/spec/spec_helper.rb +36 -5
- metadata +34 -12
- data/lib/epitools/basetypes.rb +0 -1135
- data/lib/epitools/string_to_proc.rb +0 -78
@@ -1,78 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
unless public_method_defined? :to_proc
|
4
|
-
|
5
|
-
#
|
6
|
-
# String#to_proc
|
7
|
-
#
|
8
|
-
# See http://weblog.raganwald.com/2007/10/stringtoproc.html
|
9
|
-
#
|
10
|
-
# Ported from the String Lambdas in Oliver Steele's Functional Javascript
|
11
|
-
# http://osteele.com/sources/javascript/functional/
|
12
|
-
#
|
13
|
-
# This work is licensed under the MIT License:
|
14
|
-
#
|
15
|
-
# (c) 2007 Reginald Braithwaite
|
16
|
-
# Portions Copyright (c) 2006 Oliver Steele
|
17
|
-
#
|
18
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
19
|
-
# a copy of this software and associated documentation files (the
|
20
|
-
# "Software"), to deal in the Software without restriction, including
|
21
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
22
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
23
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
24
|
-
# the following conditions:
|
25
|
-
#
|
26
|
-
# The above copyright notice and this permission notice shall be
|
27
|
-
# included in all copies or substantial portions of the Software.
|
28
|
-
#
|
29
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
30
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
31
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
32
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
33
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
34
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
35
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
36
|
-
#
|
37
|
-
def to_proc &block
|
38
|
-
params = []
|
39
|
-
expr = self
|
40
|
-
sections = expr.split(/\s*->\s*/m)
|
41
|
-
if sections.length > 1 then
|
42
|
-
eval_block(sections.reverse!.inject { |e, p| "(Proc.new { |#{p.split(/\s/).join(', ')}| #{e} })" }, block)
|
43
|
-
elsif expr.match(/\b_\b/)
|
44
|
-
eval_block("Proc.new { |_| #{expr} }", block)
|
45
|
-
else
|
46
|
-
leftSection = expr.match(/^\s*(?:[+*\/%&|\^\.=<>\[]|!=)/m)
|
47
|
-
rightSection = expr.match(/[+\-*\/%&|\^\.=<>!]\s*$/m)
|
48
|
-
if leftSection || rightSection then
|
49
|
-
if (leftSection) then
|
50
|
-
params.push('$left')
|
51
|
-
expr = '$left' + expr
|
52
|
-
end
|
53
|
-
if (rightSection) then
|
54
|
-
params.push('$right')
|
55
|
-
expr = expr + '$right'
|
56
|
-
end
|
57
|
-
else
|
58
|
-
self.gsub(
|
59
|
-
/(?:\b[A-Z]|\.[a-zA-Z_$])[a-zA-Z_$\d]*|[a-zA-Z_$][a-zA-Z_$\d]*:|self|arguments|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/, ''
|
60
|
-
).scan(
|
61
|
-
/([a-z_$][a-z_$\d]*)/i
|
62
|
-
) do |v|
|
63
|
-
params.push(v) unless params.include?(v)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
eval_block("Proc.new { |#{params.join(', ')}| #{expr} }", block)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def eval_block(code, block)
|
73
|
-
eval code, block && block.binding
|
74
|
-
end
|
75
|
-
|
76
|
-
end # unless public_method_defined? :to_proc
|
77
|
-
|
78
|
-
end
|