zucker 8 → 9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/MIT-LICENSE +1 -1
- data/README +1 -1
- data/Rakefile +33 -40
- data/desc/alias_for.yaml +17 -0
- data/desc/aliases.yaml +18 -0
- data/desc/array.yaml +13 -0
- data/desc/array_to_proc.yaml +16 -0
- data/desc/binding.yaml +22 -0
- data/desc/blank.yaml +9 -0
- data/desc/cc.yaml +10 -0
- data/desc/class_to_proc.yaml +11 -0
- data/desc/dd.yaml +23 -0
- data/desc/egonil.yaml +15 -0
- data/desc/engine.yaml +15 -0
- data/desc/enumerable.yaml +10 -0
- data/desc/file.yaml +15 -0
- data/desc/hash.yaml +14 -0
- data/desc/hash_to_proc.yaml +10 -0
- data/desc/info.yaml +20 -0
- data/desc/iterate.yaml +16 -0
- data/desc/ivars.yaml +19 -0
- data/desc/kernel.yaml +14 -0
- data/desc/mcopy.yaml +11 -0
- data/desc/mm.yaml +15 -0
- data/desc/not.yaml +11 -0
- data/desc/oo.yaml +10 -0
- data/desc/os.yaml +19 -0
- data/desc/qq.yaml +11 -0
- data/desc/regexp_to_proc.yaml +12 -0
- data/desc/regexp_visualize.yaml +23 -0
- data/desc/sandbox.yaml +12 -0
- data/desc/square_brackets_for.yaml +22 -0
- data/desc/string.yaml +23 -0
- data/desc/tap.yaml +17 -0
- data/desc/unary.yaml +15 -0
- data/desc/union.yaml +10 -0
- data/desc/version.yaml +28 -0
- data/doc/zucker_doc.html +2688 -0
- data/doc/zucker_doc.rb +553 -0
- data/lib/zucker.rb +10 -9
- data/lib/zucker/array2proc.rb +2 -18
- data/lib/zucker/{2/array2proc.rb → array_to_proc.rb} +0 -0
- data/lib/zucker/binding.rb +4 -5
- data/lib/zucker/cc.rb +7 -2
- data/lib/zucker/class2proc.rb +2 -12
- data/lib/zucker/{1/class2proc.rb → class_to_proc.rb} +0 -0
- data/lib/zucker/file.rb +22 -0
- data/lib/zucker/hash2proc.rb +2 -16
- data/lib/zucker/{1/hash2proc.rb → hash_to_proc.rb} +0 -0
- data/lib/zucker/kernel.rb +4 -2
- data/lib/zucker/mm.rb +14 -8
- data/lib/zucker/regexp2proc.rb +2 -12
- data/lib/zucker/{1/regexp2proc.rb → regexp_to_proc.rb} +0 -0
- data/lib/zucker/regexp_visualize.rb +26 -0
- data/lib/zucker/sandbox.rb +1 -11
- data/spec/alias_for_spec.rb +117 -0
- data/spec/aliases_spec.rb +13 -0
- data/spec/array_spec.rb +23 -0
- data/spec/array_to_proc_spec.rb +12 -0
- data/spec/binding_spec.rb +6 -0
- data/spec/blank_spec.rb +20 -0
- data/spec/cc_spec.rb +6 -0
- data/spec/class_to_proc_spec.rb +9 -0
- data/spec/dd_spec.rb +37 -0
- data/spec/egonil_spec.rb +32 -0
- data/spec/engine_spec.rb +11 -0
- data/spec/enumerable_spec.rb +8 -0
- data/spec/file_spec.rb +30 -0
- data/spec/hash_spec.rb +25 -0
- data/spec/hash_to_proc_spec.rb +12 -0
- data/spec/info_spec.rb +8 -0
- data/spec/iterate_spec.rb +59 -0
- data/spec/ivars_spec.rb +20 -0
- data/spec/kernel_spec.rb +37 -0
- data/spec/mcopy_spec.rb +13 -0
- data/spec/mm_spec.rb +6 -0
- data/spec/not_spec.rb +12 -0
- data/spec/oo_spec.rb +6 -0
- data/spec/os_spec.rb +37 -0
- data/spec/qq_spec.rb +19 -0
- data/spec/regexp_to_proc_spec.rb +9 -0
- data/spec/regexp_visualize_spec.rb +38 -0
- data/spec/sandbox_spec.rb +12 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/square_brackets_for_spec.rb +59 -0
- data/spec/string_spec.rb +65 -0
- data/spec/tap_spec.rb +18 -0
- data/spec/unary_spec.rb +26 -0
- data/spec/union_spec.rb +17 -0
- data/spec/version_spec.rb +55 -0
- data/zucker.gemspec +21 -0
- metadata +139 -323
- data/lib/zucker/1/D.rb +0 -21
- data/lib/zucker/1/aliases.rb +0 -30
- data/lib/zucker/1/all.rb +0 -8
- data/lib/zucker/1/array.rb +0 -19
- data/lib/zucker/1/array2proc.rb +0 -12
- data/lib/zucker/1/binding.rb +0 -27
- data/lib/zucker/1/blank.rb +0 -28
- data/lib/zucker/1/debug.rb +0 -6
- data/lib/zucker/1/default.rb +0 -27
- data/lib/zucker/1/egonil.rb +0 -16
- data/lib/zucker/1/enumerable.rb +0 -14
- data/lib/zucker/1/hash.rb +0 -21
- data/lib/zucker/1/iterate.rb +0 -25
- data/lib/zucker/1/ivars.rb +0 -28
- data/lib/zucker/1/kernel.rb +0 -22
- data/lib/zucker/1/mcopy.rb +0 -11
- data/lib/zucker/1/mm.rb +0 -33
- data/lib/zucker/1/sandbox.rb +0 -17
- data/lib/zucker/1/square_brackets_for.rb +0 -22
- data/lib/zucker/1/string.rb +0 -27
- data/lib/zucker/1/unary.rb +0 -24
- data/lib/zucker/1/union.rb +0 -16
- data/lib/zucker/2/D.rb +0 -21
- data/lib/zucker/2/aliases.rb +0 -30
- data/lib/zucker/2/all.rb +0 -8
- data/lib/zucker/2/array.rb +0 -19
- data/lib/zucker/2/binding.rb +0 -27
- data/lib/zucker/2/blank.rb +0 -28
- data/lib/zucker/2/class2proc.rb +0 -12
- data/lib/zucker/2/debug.rb +0 -6
- data/lib/zucker/2/default.rb +0 -27
- data/lib/zucker/2/egonil.rb +0 -16
- data/lib/zucker/2/enumerable.rb +0 -14
- data/lib/zucker/2/hash.rb +0 -21
- data/lib/zucker/2/hash2proc.rb +0 -16
- data/lib/zucker/2/info.rb +0 -166
- data/lib/zucker/2/iterate.rb +0 -25
- data/lib/zucker/2/ivars.rb +0 -28
- data/lib/zucker/2/kernel.rb +0 -20
- data/lib/zucker/2/mcopy.rb +0 -11
- data/lib/zucker/2/mm.rb +0 -33
- data/lib/zucker/2/regexp2proc.rb +0 -12
- data/lib/zucker/2/sandbox.rb +0 -21
- data/lib/zucker/2/square_brackets_for.rb +0 -22
- data/lib/zucker/2/string.rb +0 -27
- data/lib/zucker/2/unary.rb +0 -24
- data/lib/zucker/2/union.rb +0 -16
- data/lib/zucker/3/D.rb +0 -21
- data/lib/zucker/3/alias_for.rb +0 -21
- data/lib/zucker/3/aliases.rb +0 -30
- data/lib/zucker/3/all.rb +0 -8
- data/lib/zucker/3/array.rb +0 -25
- data/lib/zucker/3/array2proc.rb +0 -18
- data/lib/zucker/3/binding.rb +0 -27
- data/lib/zucker/3/blank.rb +0 -28
- data/lib/zucker/3/class2proc.rb +0 -12
- data/lib/zucker/3/debug.rb +0 -8
- data/lib/zucker/3/default.rb +0 -37
- data/lib/zucker/3/egonil.rb +0 -16
- data/lib/zucker/3/enumerable.rb +0 -14
- data/lib/zucker/3/hash.rb +0 -21
- data/lib/zucker/3/hash2proc.rb +0 -16
- data/lib/zucker/3/info.rb +0 -169
- data/lib/zucker/3/iterate.rb +0 -25
- data/lib/zucker/3/ivars.rb +0 -28
- data/lib/zucker/3/kernel.rb +0 -50
- data/lib/zucker/3/mcopy.rb +0 -10
- data/lib/zucker/3/mm.rb +0 -33
- data/lib/zucker/3/not.rb +0 -19
- data/lib/zucker/3/regexp2proc.rb +0 -12
- data/lib/zucker/3/sandbox.rb +0 -21
- data/lib/zucker/3/square_brackets_for.rb +0 -22
- data/lib/zucker/3/string.rb +0 -49
- data/lib/zucker/3/tap.rb +0 -11
- data/lib/zucker/3/unary.rb +0 -24
- data/lib/zucker/3/union.rb +0 -16
- data/lib/zucker/4/D.rb +0 -21
- data/lib/zucker/4/alias_for.rb +0 -21
- data/lib/zucker/4/aliases.rb +0 -35
- data/lib/zucker/4/all.rb +0 -8
- data/lib/zucker/4/array.rb +0 -25
- data/lib/zucker/4/array2proc.rb +0 -18
- data/lib/zucker/4/binding.rb +0 -27
- data/lib/zucker/4/blank.rb +0 -28
- data/lib/zucker/4/class2proc.rb +0 -12
- data/lib/zucker/4/debug.rb +0 -8
- data/lib/zucker/4/default.rb +0 -40
- data/lib/zucker/4/egonil.rb +0 -16
- data/lib/zucker/4/engine.rb +0 -69
- data/lib/zucker/4/enumerable.rb +0 -14
- data/lib/zucker/4/hash.rb +0 -21
- data/lib/zucker/4/hash2proc.rb +0 -16
- data/lib/zucker/4/info.rb +0 -173
- data/lib/zucker/4/iterate.rb +0 -25
- data/lib/zucker/4/ivars.rb +0 -28
- data/lib/zucker/4/kernel.rb +0 -27
- data/lib/zucker/4/mcopy.rb +0 -10
- data/lib/zucker/4/mm.rb +0 -33
- data/lib/zucker/4/not.rb +0 -19
- data/lib/zucker/4/os.rb +0 -50
- data/lib/zucker/4/q.rb +0 -7
- data/lib/zucker/4/regexp2proc.rb +0 -12
- data/lib/zucker/4/sandbox.rb +0 -23
- data/lib/zucker/4/square_brackets_for.rb +0 -22
- data/lib/zucker/4/string.rb +0 -54
- data/lib/zucker/4/tap.rb +0 -11
- data/lib/zucker/4/unary.rb +0 -24
- data/lib/zucker/4/union.rb +0 -16
- data/lib/zucker/4/version.rb +0 -115
- data/lib/zucker/5/alias_for.rb +0 -21
- data/lib/zucker/5/aliases.rb +0 -51
- data/lib/zucker/5/all.rb +0 -4
- data/lib/zucker/5/array.rb +0 -25
- data/lib/zucker/5/array2proc.rb +0 -18
- data/lib/zucker/5/binding.rb +0 -34
- data/lib/zucker/5/blank.rb +0 -28
- data/lib/zucker/5/cc.rb +0 -25
- data/lib/zucker/5/class2proc.rb +0 -12
- data/lib/zucker/5/control.rb +0 -4
- data/lib/zucker/5/dd.rb +0 -24
- data/lib/zucker/5/debug.rb +0 -4
- data/lib/zucker/5/default.rb +0 -4
- data/lib/zucker/5/egonil.rb +0 -16
- data/lib/zucker/5/engine.rb +0 -69
- data/lib/zucker/5/enumerable.rb +0 -14
- data/lib/zucker/5/env.rb +0 -4
- data/lib/zucker/5/extensions.rb +0 -4
- data/lib/zucker/5/hash.rb +0 -27
- data/lib/zucker/5/hash2proc.rb +0 -16
- data/lib/zucker/5/info.rb +0 -177
- data/lib/zucker/5/iterate.rb +0 -26
- data/lib/zucker/5/ivars.rb +0 -28
- data/lib/zucker/5/kernel.rb +0 -34
- data/lib/zucker/5/mcopy.rb +0 -10
- data/lib/zucker/5/mm.rb +0 -34
- data/lib/zucker/5/not.rb +0 -19
- data/lib/zucker/5/object.rb +0 -4
- data/lib/zucker/5/oo.rb +0 -17
- data/lib/zucker/5/os.rb +0 -49
- data/lib/zucker/5/qq.rb +0 -12
- data/lib/zucker/5/regexp2proc.rb +0 -12
- data/lib/zucker/5/sandbox.rb +0 -25
- data/lib/zucker/5/shortcuts.rb +0 -4
- data/lib/zucker/5/square_brackets_for.rb +0 -21
- data/lib/zucker/5/string.rb +0 -54
- data/lib/zucker/5/tap.rb +0 -11
- data/lib/zucker/5/to_proc.rb +0 -4
- data/lib/zucker/5/unary.rb +0 -24
- data/lib/zucker/5/union.rb +0 -16
- data/lib/zucker/5/version.rb +0 -118
- data/lib/zucker/6/alias_for.rb +0 -21
- data/lib/zucker/6/aliases.rb +0 -51
- data/lib/zucker/6/all.rb +0 -4
- data/lib/zucker/6/array.rb +0 -25
- data/lib/zucker/6/array2proc.rb +0 -18
- data/lib/zucker/6/binding.rb +0 -34
- data/lib/zucker/6/blank.rb +0 -28
- data/lib/zucker/6/cc.rb +0 -25
- data/lib/zucker/6/class2proc.rb +0 -12
- data/lib/zucker/6/control.rb +0 -4
- data/lib/zucker/6/dd.rb +0 -23
- data/lib/zucker/6/debug.rb +0 -4
- data/lib/zucker/6/default.rb +0 -4
- data/lib/zucker/6/egonil.rb +0 -27
- data/lib/zucker/6/engine.rb +0 -68
- data/lib/zucker/6/enumerable.rb +0 -14
- data/lib/zucker/6/env.rb +0 -4
- data/lib/zucker/6/extensions.rb +0 -4
- data/lib/zucker/6/hash.rb +0 -27
- data/lib/zucker/6/hash2proc.rb +0 -16
- data/lib/zucker/6/info.rb +0 -192
- data/lib/zucker/6/iterate.rb +0 -27
- data/lib/zucker/6/ivars.rb +0 -28
- data/lib/zucker/6/kernel.rb +0 -34
- data/lib/zucker/6/mcopy.rb +0 -10
- data/lib/zucker/6/mm.rb +0 -34
- data/lib/zucker/6/not.rb +0 -19
- data/lib/zucker/6/object.rb +0 -4
- data/lib/zucker/6/oo.rb +0 -17
- data/lib/zucker/6/os.rb +0 -54
- data/lib/zucker/6/qq.rb +0 -12
- data/lib/zucker/6/regexp2proc.rb +0 -12
- data/lib/zucker/6/sandbox.rb +0 -25
- data/lib/zucker/6/shortcuts.rb +0 -4
- data/lib/zucker/6/square_brackets_for.rb +0 -21
- data/lib/zucker/6/string.rb +0 -54
- data/lib/zucker/6/tap.rb +0 -11
- data/lib/zucker/6/to_proc.rb +0 -4
- data/lib/zucker/6/unary.rb +0 -24
- data/lib/zucker/6/union.rb +0 -16
- data/lib/zucker/6/version.rb +0 -118
- data/lib/zucker/7/alias_for.rb +0 -21
- data/lib/zucker/7/aliases.rb +0 -51
- data/lib/zucker/7/all.rb +0 -4
- data/lib/zucker/7/array.rb +0 -25
- data/lib/zucker/7/array2proc.rb +0 -18
- data/lib/zucker/7/binding.rb +0 -34
- data/lib/zucker/7/blank.rb +0 -28
- data/lib/zucker/7/cc.rb +0 -25
- data/lib/zucker/7/class2proc.rb +0 -12
- data/lib/zucker/7/control.rb +0 -4
- data/lib/zucker/7/dd.rb +0 -23
- data/lib/zucker/7/debug.rb +0 -4
- data/lib/zucker/7/default.rb +0 -4
- data/lib/zucker/7/egonil.rb +0 -27
- data/lib/zucker/7/engine.rb +0 -68
- data/lib/zucker/7/enumerable.rb +0 -14
- data/lib/zucker/7/env.rb +0 -4
- data/lib/zucker/7/extensions.rb +0 -4
- data/lib/zucker/7/hash.rb +0 -27
- data/lib/zucker/7/hash2proc.rb +0 -16
- data/lib/zucker/7/info.rb +0 -192
- data/lib/zucker/7/iterate.rb +0 -27
- data/lib/zucker/7/ivars.rb +0 -28
- data/lib/zucker/7/kernel.rb +0 -34
- data/lib/zucker/7/mcopy.rb +0 -10
- data/lib/zucker/7/mm.rb +0 -34
- data/lib/zucker/7/not.rb +0 -19
- data/lib/zucker/7/object.rb +0 -4
- data/lib/zucker/7/oo.rb +0 -17
- data/lib/zucker/7/os.rb +0 -54
- data/lib/zucker/7/qq.rb +0 -12
- data/lib/zucker/7/regexp2proc.rb +0 -12
- data/lib/zucker/7/sandbox.rb +0 -25
- data/lib/zucker/7/shortcuts.rb +0 -4
- data/lib/zucker/7/square_brackets_for.rb +0 -21
- data/lib/zucker/7/string.rb +0 -54
- data/lib/zucker/7/tap.rb +0 -11
- data/lib/zucker/7/to_proc.rb +0 -4
- data/lib/zucker/7/unary.rb +0 -24
- data/lib/zucker/7/union.rb +0 -16
- data/lib/zucker/7/version.rb +0 -118
- data/lib/zucker/8/alias_for.rb +0 -21
- data/lib/zucker/8/aliases.rb +0 -51
- data/lib/zucker/8/all.rb +0 -4
- data/lib/zucker/8/array.rb +0 -25
- data/lib/zucker/8/array2proc.rb +0 -18
- data/lib/zucker/8/binding.rb +0 -33
- data/lib/zucker/8/blank.rb +0 -28
- data/lib/zucker/8/cc.rb +0 -25
- data/lib/zucker/8/class2proc.rb +0 -12
- data/lib/zucker/8/control.rb +0 -4
- data/lib/zucker/8/dd.rb +0 -23
- data/lib/zucker/8/debug.rb +0 -4
- data/lib/zucker/8/default.rb +0 -4
- data/lib/zucker/8/egonil.rb +0 -27
- data/lib/zucker/8/engine.rb +0 -68
- data/lib/zucker/8/enumerable.rb +0 -14
- data/lib/zucker/8/env.rb +0 -4
- data/lib/zucker/8/extensions.rb +0 -4
- data/lib/zucker/8/hash.rb +0 -27
- data/lib/zucker/8/hash2proc.rb +0 -16
- data/lib/zucker/8/info.rb +0 -192
- data/lib/zucker/8/iterate.rb +0 -27
- data/lib/zucker/8/ivars.rb +0 -28
- data/lib/zucker/8/kernel.rb +0 -34
- data/lib/zucker/8/mcopy.rb +0 -10
- data/lib/zucker/8/mm.rb +0 -34
- data/lib/zucker/8/not.rb +0 -19
- data/lib/zucker/8/object.rb +0 -4
- data/lib/zucker/8/oo.rb +0 -17
- data/lib/zucker/8/os.rb +0 -54
- data/lib/zucker/8/qq.rb +0 -12
- data/lib/zucker/8/regexp2proc.rb +0 -12
- data/lib/zucker/8/sandbox.rb +0 -25
- data/lib/zucker/8/shortcuts.rb +0 -4
- data/lib/zucker/8/square_brackets_for.rb +0 -21
- data/lib/zucker/8/string.rb +0 -54
- data/lib/zucker/8/tap.rb +0 -11
- data/lib/zucker/8/to_proc.rb +0 -4
- data/lib/zucker/8/unary.rb +0 -24
- data/lib/zucker/8/union.rb +0 -16
- data/lib/zucker/8/version.rb +0 -118
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'zucker/array'
|
2
|
+
|
3
|
+
describe 'Array#^' do
|
4
|
+
it 'should do an exclusive or' do
|
5
|
+
a = [1,2,3,4]
|
6
|
+
b = [3,4,5,6]
|
7
|
+
(a^b).should == [1,2,5,6]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Array#sum' do
|
12
|
+
it 'should sum the array' do
|
13
|
+
[1,2,3,4,5].sum.should == 15
|
14
|
+
%w|More Ruby|.sum.should == 'MoreRuby'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Array#chrs' do
|
19
|
+
it 'should convert the array to a string, using each element as ord value for the char' do
|
20
|
+
[72, 97, 108, 108, 111].chrs.should == 'Hallo'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'zucker/array_to_proc'
|
2
|
+
|
3
|
+
describe 'Array#to_proc' do
|
4
|
+
it 'should call the method of the first symbol, using the remaining elements as paramaters' do
|
5
|
+
[1,2,3,4].map( &[:to_s, 2] ).should == ["1", "10", "11", "100"]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should convert each element to a proc and chain it, if the first parameter is an array" do
|
9
|
+
[1,2,3,4].map( &[[:*,2],[:+,4]] ).should == [1,2,3,4].map{|i| i*2 + 4 }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
data/spec/blank_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'zucker/blank'
|
2
|
+
|
3
|
+
describe 'Object#blank?' do
|
4
|
+
it 'should be blank for blank values' do
|
5
|
+
blank_values = [ nil, false, '', ' ', " \n\t \r ", [], {}, // ]
|
6
|
+
|
7
|
+
blank_values.each{ |blank|
|
8
|
+
blank.blank?.should == true
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should not be blank for non blank values' do
|
13
|
+
present_values = [ Object.new, true, 0, 1, 'a', [nil], { nil => nil } ]
|
14
|
+
|
15
|
+
present_values.each{ |present|
|
16
|
+
present.blank?.should == false
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/spec/cc_spec.rb
ADDED
data/spec/dd_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'zucker/dd'
|
2
|
+
|
3
|
+
describe 'Object#d' do
|
4
|
+
|
5
|
+
let :a do
|
6
|
+
[ 1, "1", 2..5, [], {:hallo => :du}, nil, true ]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not change the object's value" do
|
10
|
+
capture_stdout do
|
11
|
+
a.each{ |e|
|
12
|
+
(e.d).should == e
|
13
|
+
}
|
14
|
+
|
15
|
+
a.each{ |e|
|
16
|
+
(e.d{|value| "This is a: #{value}"}).should == e
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should puts .inspect if no block is given (and not change the object's value)" do
|
22
|
+
capture_stdout do
|
23
|
+
a[0].d
|
24
|
+
a[1].d
|
25
|
+
a[6].d
|
26
|
+
end.should == %{1\n"1"\ntrue\n}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should puts the block if it is given (and not change the object's value)" do
|
30
|
+
capture_stdout do
|
31
|
+
a[0].d{|value| "This is a: #{value}"}
|
32
|
+
a[1].d{|value| "This is a: #{value}"}
|
33
|
+
a[6].d{|value| "This is a: #{value}"}
|
34
|
+
end.should == %{This is a: 1\nThis is a: 1\nThis is a: true\n}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/spec/egonil_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'zucker/egonil'
|
2
|
+
|
3
|
+
describe 'egonil' do
|
4
|
+
it 'should not raise nil exceptions in the block' do
|
5
|
+
proc do
|
6
|
+
egonil{ nil.some_methods.that[:do].not.exist }
|
7
|
+
end.should_not raise_exception
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should restore default behaviour after the block' do
|
11
|
+
proc do
|
12
|
+
egonil{ nil.some_methods.that[:do].not.exist }
|
13
|
+
end.should_not raise_exception
|
14
|
+
|
15
|
+
proc do
|
16
|
+
nil.a_method
|
17
|
+
end.should raise_exception NoMethodError
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'raise NoMethodError for non-nil objects' do
|
21
|
+
proc do
|
22
|
+
egonil{ 5.a_method }
|
23
|
+
end.should raise_exception NoMethodError
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise other Exceptions' do
|
27
|
+
proc do
|
28
|
+
egonil{ 5 / 0 }
|
29
|
+
end.should raise_exception ZeroDivisionError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
data/spec/engine_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'zucker/engine'
|
2
|
+
|
3
|
+
describe 'RubyEngine' do
|
4
|
+
it 'should display the current ruby interpreter (to_s)' do
|
5
|
+
RubyEngine
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should create many method aliases for asking for a specific interpreter' do
|
9
|
+
# please see the source or description file
|
10
|
+
end
|
11
|
+
end
|
data/spec/file_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'zucker/file'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe 'File#gsub' do
|
5
|
+
it 'should read filename in arg1, substitute every key in the arg2 with its value and save the file'
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'File#delete!' do
|
9
|
+
let :random_filename do
|
10
|
+
'test_' + (0..20).map{|e| [*'a'..'z'].send RUBY_VERSION > '1.9' ? :sample : :choice }*''
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should delete the filename given as argument if it exists + return non-nil' do
|
14
|
+
FileUtils.touch random_filename
|
15
|
+
res = false
|
16
|
+
proc do
|
17
|
+
res = File.delete! random_filename
|
18
|
+
end.should_not raise_exception
|
19
|
+
res.should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should do nothing if the filename given as argument does not exist + return nil' do
|
23
|
+
res = false
|
24
|
+
proc do
|
25
|
+
res = File.delete! random_filename
|
26
|
+
end.should_not raise_exception
|
27
|
+
res.should be_false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/spec/hash_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'zucker/hash'
|
2
|
+
|
3
|
+
describe 'Hash.zip' do
|
4
|
+
it 'should zip together both given enumerables and take them as key=>values for a new hash' do
|
5
|
+
Hash.zip( [1,2,3], [4,5,6] ).should == { 1=>4, 2=>5, 3=>6 }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'Hash#<<' do
|
10
|
+
it 'should append new elements to the hash' do
|
11
|
+
a = { 1=>4, 2=>5, 3=>6 }
|
12
|
+
a << { 4=>7 }
|
13
|
+
a << [5, 8]
|
14
|
+
a.should == { 1=>4, 2=>5, 3=>6, 4=>7, 5=>8 }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Hash#&' do
|
19
|
+
it 'should select a sub hash containt only equal key-value pairs' do
|
20
|
+
a = { 1=>4, 2=>5, 3=>6 }
|
21
|
+
b= { 1=>4, 2=>7 }
|
22
|
+
(a & b).should == { 1=>4 }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'zucker/hash_to_proc'
|
2
|
+
|
3
|
+
describe 'Hash#to_proc' do
|
4
|
+
it 'should run the proc given in the value for a key in the hash' do
|
5
|
+
[1,2,3,4].map(&{
|
6
|
+
4 => :to_s,
|
7
|
+
# 3 => [:to_s, 2] # "11" => if array2proc is used
|
8
|
+
2 => lambda {|e| e + 1000}
|
9
|
+
}).should == [1, 1002, 3, "4"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
data/spec/info_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'zucker/iterate'
|
2
|
+
|
3
|
+
describe 'Object#iterate' do
|
4
|
+
let :a do [1, 2, 3] end
|
5
|
+
let :b do %w|a b c d| end
|
6
|
+
let :res do Hash.new {[]} end
|
7
|
+
|
8
|
+
it 'should behave like Enumerable#each for a single argument' do
|
9
|
+
iterate a do |ele|
|
10
|
+
res[:iter] << ele
|
11
|
+
end
|
12
|
+
|
13
|
+
a.each do |ele|
|
14
|
+
res[:each] << ele
|
15
|
+
end
|
16
|
+
|
17
|
+
res[:iter].should == res[:each]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should pass the right params to the block' do
|
21
|
+
res = Hash.new {[]} # TODO: why?
|
22
|
+
res[:iter_a_b] = [] # ....
|
23
|
+
res[:iter_b_a] = [] # ....
|
24
|
+
|
25
|
+
|
26
|
+
iterate a, b do |e,f|
|
27
|
+
res[:iter_a_b] << [e, f]
|
28
|
+
end
|
29
|
+
|
30
|
+
res[:iter_a_b].should == [
|
31
|
+
[1, 'a'],
|
32
|
+
[2, 'b'],
|
33
|
+
[3, 'c'],
|
34
|
+
[nil, 'd'],
|
35
|
+
]
|
36
|
+
|
37
|
+
iterate b, a do |e,f|
|
38
|
+
res[:iter_b_a] << [e, f]
|
39
|
+
end
|
40
|
+
|
41
|
+
res[:iter_b_a].should == [
|
42
|
+
['a', 1],
|
43
|
+
['b', 2],
|
44
|
+
['c', 3],
|
45
|
+
['d', nil],
|
46
|
+
]
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return enumerators if no block is applied' do
|
51
|
+
res = Hash.new {[]} # TODO: why?
|
52
|
+
res[:iter_a_b] = [] # ....
|
53
|
+
res[:iter_b_a] = [] # ....
|
54
|
+
|
55
|
+
enumerator = iterate a,b
|
56
|
+
enumerator.should be_kind_of(RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator)
|
57
|
+
enumerator.to_a.should == [[1,'a'], [2,'b'], [3,'c'], [nil, 'd']]
|
58
|
+
end
|
59
|
+
end
|
data/spec/ivars_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'zucker/ivars'
|
2
|
+
|
3
|
+
describe 'instance_variables_from' do
|
4
|
+
it 'should tansform the given parameter to instance variables' do
|
5
|
+
def a_method(a = 1, b = 2)
|
6
|
+
instance_variables_from binding # assigns @a and @b
|
7
|
+
|
8
|
+
params = {:c => 3, :d => 4}
|
9
|
+
ivars params # # assigns @c and @d
|
10
|
+
end
|
11
|
+
|
12
|
+
a_method
|
13
|
+
@a.should == 1
|
14
|
+
@b.should == 2
|
15
|
+
@c.should == 3
|
16
|
+
@d.should == 4
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/spec/kernel_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'zucker/kernel'
|
2
|
+
|
3
|
+
describe 'activate_warnings!' do
|
4
|
+
it 'should set $VERBOSE to true' do
|
5
|
+
activate_warnings!
|
6
|
+
$VERBOSE.should == true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'deactivate_warnings!' do
|
11
|
+
it 'should set $VERBOSE to false' do
|
12
|
+
deactivate_warnings!
|
13
|
+
$VERBOSE.should == false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'library?' do
|
18
|
+
it 'should return false if the file is invoked directly' do
|
19
|
+
library?.should == ( __FILE__ != $PROGRAM_NAME )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'executed_directly?' do
|
24
|
+
it 'should return true if the file is invoked directly' do
|
25
|
+
executed_directly?.should == ( __FILE__ == $PROGRAM_NAME )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'irb?' do
|
30
|
+
it 'should return true if called in IRB' do; end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'ignore_sigint!' do
|
34
|
+
it 'should catch ctrl+c signals' do; end
|
35
|
+
end
|
36
|
+
|
37
|
+
# J-_-L
|
data/spec/mcopy_spec.rb
ADDED
data/spec/mm_spec.rb
ADDED
data/spec/not_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
if defined? BasicObject # 1.9 only
|
2
|
+
|
3
|
+
require 'zucker/not'
|
4
|
+
|
5
|
+
describe 'Object#not' do
|
6
|
+
it "should return an object on which all methods are redirected to it's receiver object, but return an inverted boolean" do
|
7
|
+
[1,2,3].not.empty?.should == true
|
8
|
+
nil.not.nil?.should == false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
data/spec/oo_spec.rb
ADDED
data/spec/os_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'zucker/os'
|
2
|
+
|
3
|
+
describe 'OS' do
|
4
|
+
it 'should display the used operation system (to_s)' do; end
|
5
|
+
end
|
6
|
+
|
7
|
+
describe 'linux?' do
|
8
|
+
it 'should return true if OS is a linux' do; end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'mac?' do
|
12
|
+
it 'should return true if OS is a mac or darwin' do; end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'bsd?' do
|
16
|
+
it 'should return true if OS is a bsd' do; end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'windows?' do
|
20
|
+
it 'should return true if OS is a windows' do; end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'solaris?' do
|
24
|
+
it 'should return true if OS is a solaris or sunos' do; end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'posix?' do
|
28
|
+
it 'should return true if OS is posix compatible' do; end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'OS.is?' do
|
32
|
+
it "should test if RbConfig::CONFIG['host_os'] matches the regex (boolean value)" do
|
33
|
+
OS.is?(/linux/).should ==
|
34
|
+
!!( RbConfig::CONFIG['host_os'] =~ /linux/ )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|