epitools 0.1.9 → 0.1.10
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/VERSION +1 -1
- data/epitools.gemspec +8 -8
- data/lib/epitools/basetypes.rb +26 -26
- data/lib/epitools/string_to_proc.rb +39 -32
- data/spec/basetypes_spec.rb +8 -15
- metadata +8 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/epitools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{epitools}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["epitron"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-16}
|
13
13
|
s.description = %q{Miscellaneous utility libraries to make my life easier.}
|
14
14
|
s.email = %q{chris@ill-logic.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -54,14 +54,14 @@ Gem::Specification.new do |s|
|
|
54
54
|
s.rubygems_version = %q{1.3.7}
|
55
55
|
s.summary = %q{NOT UTILS... METILS!}
|
56
56
|
s.test_files = [
|
57
|
-
"spec/
|
58
|
-
"spec/ratio_spec.rb",
|
59
|
-
"spec/metaclass_spec.rb",
|
60
|
-
"spec/basetypes_spec.rb",
|
57
|
+
"spec/basetypes_spec.rb",
|
61
58
|
"spec/lcs_spec.rb",
|
62
|
-
"spec/
|
59
|
+
"spec/metaclass_spec.rb",
|
63
60
|
"spec/permutations_spec.rb",
|
64
|
-
"spec/
|
61
|
+
"spec/rash_spec.rb",
|
62
|
+
"spec/ratio_spec.rb",
|
63
|
+
"spec/spec_helper.rb",
|
64
|
+
"spec/zopen_spec.rb"
|
65
65
|
]
|
66
66
|
|
67
67
|
if s.respond_to? :specification_version then
|
data/lib/epitools/basetypes.rb
CHANGED
@@ -203,7 +203,7 @@ module Enumerable
|
|
203
203
|
# The same as "map", except that if an element is an Array or Enumerable, map is called
|
204
204
|
# recursively on that element.
|
205
205
|
#
|
206
|
-
# eg: [ [1,2], [3,4] ].
|
206
|
+
# eg: [ [1,2], [3,4] ].map_recursively{|e| e ** 2 } #=> [ [1,4], [9,16] ]
|
207
207
|
#
|
208
208
|
def recursive_map(*args, &block)
|
209
209
|
map(*args) do |e|
|
@@ -215,8 +215,8 @@ module Enumerable
|
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
|
-
alias_method :map_recursive, :recursive_map
|
219
218
|
alias_method :map_recursively, :recursive_map
|
219
|
+
alias_method :map_recursive, :recursive_map
|
220
220
|
|
221
221
|
|
222
222
|
#
|
@@ -407,23 +407,23 @@ end
|
|
407
407
|
|
408
408
|
|
409
409
|
|
410
|
-
#
|
411
|
-
# Magic "its" Mapping
|
412
|
-
# -------------------
|
413
|
-
#
|
414
|
-
# The pure-Ruby way:
|
415
|
-
# User.find(:all).map{|x| x.contacts.map{|y| y.last_name.capitalize }}
|
416
|
-
#
|
417
|
-
# With Symbol#to_proc:
|
418
|
-
# User.find(:all).map{|x|x.contacts.map(&:last_name).map(&:capitalize)}
|
419
|
-
#
|
420
|
-
# Magic "its" way:
|
421
|
-
# User.find(:all).map &its.contacts.map(&its.last_name.capitalize)
|
422
|
-
#
|
423
|
-
|
424
410
|
module Kernel
|
425
411
|
|
426
412
|
protected
|
413
|
+
|
414
|
+
#
|
415
|
+
# Magic "its" Mapping
|
416
|
+
# -------------------
|
417
|
+
#
|
418
|
+
# The pure-Ruby way:
|
419
|
+
# User.find(:all).map{|x| x.contacts.map{|y| y.last_name.capitalize }}
|
420
|
+
#
|
421
|
+
# With Symbol#to_proc:
|
422
|
+
# User.find(:all).map{|x|x.contacts.map(&:last_name).map(&:capitalize)}
|
423
|
+
#
|
424
|
+
# Magic "its" way:
|
425
|
+
# User.find(:all).map &its.contacts.map(&its.last_name.capitalize)
|
426
|
+
#
|
427
427
|
def it()
|
428
428
|
It.new
|
429
429
|
end
|
@@ -458,16 +458,6 @@ class BlankSlate
|
|
458
458
|
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
|
459
459
|
end
|
460
460
|
|
461
|
-
#
|
462
|
-
# Funky #not method
|
463
|
-
# -----------------
|
464
|
-
#
|
465
|
-
# >> 10.even?
|
466
|
-
# => true
|
467
|
-
# >> 10.not.even?
|
468
|
-
# => false
|
469
|
-
#
|
470
|
-
|
471
461
|
class NotWrapper < BlankSlate
|
472
462
|
def initialize(orig)
|
473
463
|
@orig = orig
|
@@ -489,9 +479,19 @@ end
|
|
489
479
|
|
490
480
|
|
491
481
|
class Object
|
482
|
+
|
483
|
+
#
|
484
|
+
# Negates a boolean, chained-method style:
|
485
|
+
#
|
486
|
+
# >> 10.even?
|
487
|
+
# => true
|
488
|
+
# >> 10.not.even?
|
489
|
+
# => false
|
490
|
+
#
|
492
491
|
def not
|
493
492
|
NotWrapper.new(self)
|
494
493
|
end
|
494
|
+
|
495
495
|
end
|
496
496
|
|
497
497
|
|
@@ -1,36 +1,39 @@
|
|
1
|
-
# String#to_proc
|
2
|
-
#
|
3
|
-
# See http://weblog.raganwald.com/2007/10/stringtoproc.html
|
4
|
-
#
|
5
|
-
# Ported from the String Lambdas in Oliver Steele's Functional Javascript
|
6
|
-
# http://osteele.com/sources/javascript/functional/
|
7
|
-
#
|
8
|
-
# This work is licensed under the MIT License:
|
9
|
-
#
|
10
|
-
# (c) 2007 Reginald Braithwaite
|
11
|
-
# Portions Copyright (c) 2006 Oliver Steele
|
12
|
-
#
|
13
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
14
|
-
# a copy of this software and associated documentation files (the
|
15
|
-
# "Software"), to deal in the Software without restriction, including
|
16
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
17
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
18
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
19
|
-
# the following conditions:
|
20
|
-
#
|
21
|
-
# The above copyright notice and this permission notice shall be
|
22
|
-
# included in all copies or substantial portions of the Software.
|
23
|
-
#
|
24
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
25
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
27
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
28
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
29
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
30
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
|
-
|
32
1
|
class String
|
2
|
+
|
33
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
|
+
#
|
34
37
|
def to_proc &block
|
35
38
|
params = []
|
36
39
|
expr = self
|
@@ -63,9 +66,13 @@ class String
|
|
63
66
|
eval_block("Proc.new { |#{params.join(', ')}| #{expr} }", block)
|
64
67
|
end
|
65
68
|
end
|
69
|
+
|
66
70
|
private
|
71
|
+
|
67
72
|
def eval_block(code, block)
|
68
73
|
eval code, block && block.binding
|
69
74
|
end
|
70
|
-
|
75
|
+
|
76
|
+
end # unless public_method_defined? :to_proc
|
77
|
+
|
71
78
|
end
|
data/spec/basetypes_spec.rb
CHANGED
@@ -60,17 +60,10 @@ describe Integer do
|
|
60
60
|
it "integer?" do
|
61
61
|
|
62
62
|
{
|
63
|
-
|
64
|
-
"
|
65
|
-
|
66
|
-
|
67
|
-
123.45 => true,
|
68
|
-
"123asdf" => false,
|
69
|
-
"asdfasdf" => false,
|
70
|
-
Object.new => false,
|
71
|
-
|
72
|
-
}.each do |object, expected_result|
|
73
|
-
object.integer?.should == expected_result
|
63
|
+
true => [ "123", "000", 123, 123.45 ],
|
64
|
+
false => [ "123asdf", "asdfasdf", Object.new, nil ]
|
65
|
+
}.each do |expected_result, objects|
|
66
|
+
objects.each { |object| object.integer?.should == expected_result }
|
74
67
|
end
|
75
68
|
|
76
69
|
end
|
@@ -97,11 +90,11 @@ end
|
|
97
90
|
describe Enumerable do
|
98
91
|
|
99
92
|
it "splits" do
|
100
|
-
[1,2,3,4,5].split_at{|e| e == 3}.should
|
101
|
-
[1,2,3,4,5].split_after{|e| e == 3}.should
|
102
|
-
[1,2,3,4,5].split_before{|e| e == 3}.should
|
93
|
+
[1,2,3,4,5].split_at {|e| e == 3}.should == [ [1,2], [4,5] ]
|
94
|
+
[1,2,3,4,5].split_after {|e| e == 3}.should == [ [1,2,3], [4,5] ]
|
95
|
+
[1,2,3,4,5].split_before {|e| e == 3}.should == [ [1,2], [3,4,5] ]
|
103
96
|
|
104
|
-
"a\nb\n---\nc\nd\n".split_at(/---/).
|
97
|
+
"a\nb\n---\nc\nd\n".split_at(/---/).map_recursively(&:strip).should == [ %w[a b], %w[c d] ]
|
105
98
|
end
|
106
99
|
|
107
100
|
it "handles nested things" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 10
|
10
|
+
version: 0.1.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- epitron
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-16 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -109,11 +109,11 @@ signing_key:
|
|
109
109
|
specification_version: 3
|
110
110
|
summary: NOT UTILS... METILS!
|
111
111
|
test_files:
|
112
|
-
- spec/rash_spec.rb
|
113
|
-
- spec/ratio_spec.rb
|
114
|
-
- spec/metaclass_spec.rb
|
115
112
|
- spec/basetypes_spec.rb
|
116
113
|
- spec/lcs_spec.rb
|
117
|
-
- spec/
|
114
|
+
- spec/metaclass_spec.rb
|
118
115
|
- spec/permutations_spec.rb
|
116
|
+
- spec/rash_spec.rb
|
117
|
+
- spec/ratio_spec.rb
|
119
118
|
- spec/spec_helper.rb
|
119
|
+
- spec/zopen_spec.rb
|