zucker 13.1 → 100.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +17 -2
- data/MIT-LICENSE +1 -1
- data/README.md +22 -0
- data/Rakefile +17 -58
- data/doc/{zucker_doc.rb → create_documentation.rb} +67 -129
- data/doc/zucker.html +1774 -0
- data/lib/zucker.rb +12 -42
- data/lib/zucker/alias_for.rb +9 -16
- data/lib/zucker/all.rb +0 -2
- data/lib/zucker/array_op.rb +15 -0
- data/lib/zucker/blank.rb +39 -21
- data/lib/zucker/camel_snake.rb +15 -0
- data/lib/zucker/constantize.rb +29 -0
- data/lib/zucker/dir_extras.rb +20 -0
- data/lib/zucker/egonil.rb +13 -24
- data/lib/zucker/file_extras.rb +33 -0
- data/lib/zucker/hash_extras.rb +11 -0
- data/lib/zucker/hash_op.rb +28 -0
- data/lib/zucker/instance_variables_from.rb +34 -0
- data/lib/zucker/iterate.rb +24 -21
- data/lib/zucker/marshal_copy.rb +11 -0
- data/lib/zucker/mash.rb +22 -0
- data/lib/zucker/ords.rb +17 -0
- data/lib/zucker/regexp_union.rb +17 -0
- data/lib/zucker/square_brackets_for.rb +12 -15
- data/lib/zucker/string_extras.rb +15 -0
- data/lib/zucker/string_op.rb +20 -0
- data/lib/zucker/tap.rb +13 -8
- data/lib/zucker/unary_conversion.rb +25 -0
- data/spec/alias_for_spec.rb +11 -73
- data/spec/array_op_spec.rb +17 -0
- data/spec/blank_spec.rb +2 -0
- data/spec/camel_snake_spec.rb +15 -0
- data/spec/constantize_spec.rb +33 -0
- data/spec/dir_extras_spec.rb +32 -0
- data/spec/egonil_spec.rb +1 -0
- data/spec/file_extras_spec.rb +57 -0
- data/spec/hash_extras_spec.rb +11 -0
- data/spec/hash_op_spec.rb +28 -0
- data/spec/instance_variables_from_spec.rb +24 -0
- data/spec/iterate_spec.rb +2 -0
- data/spec/{mcopy_spec.rb → marshal_copy_spec.rb} +5 -3
- data/spec/mash_spec.rb +17 -0
- data/spec/ords_spec.rb +15 -0
- data/spec/{union_spec.rb → regexp_union_spec.rb} +4 -2
- data/spec/square_brackets_for_spec.rb +4 -12
- data/spec/string_extras_spec.rb +20 -0
- data/spec/string_op_spec.rb +22 -0
- data/spec/tap_spec.rb +2 -0
- data/spec/{unary_spec.rb → unary_conversion_spec.rb} +4 -2
- data/zucker.gemspec +8 -18
- metadata +75 -147
- data/.gemtest +0 -0
- data/README +0 -7
- data/desc/alias_for.yaml +0 -17
- data/desc/aliases.yaml +0 -18
- data/desc/array.yaml +0 -11
- data/desc/array_to_proc.yaml +0 -16
- data/desc/binding.yaml +0 -22
- data/desc/blank.yaml +0 -11
- data/desc/case.yaml +0 -9
- data/desc/cc.yaml +0 -10
- data/desc/class_to_proc.yaml +0 -11
- data/desc/dd.yaml +0 -23
- data/desc/egonil.yaml +0 -15
- data/desc/engine.yaml +0 -15
- data/desc/enumerable.yaml +0 -10
- data/desc/file.yaml +0 -14
- data/desc/hash.yaml +0 -14
- data/desc/hash_to_proc.yaml +0 -10
- data/desc/info.yaml +0 -20
- data/desc/iterate.yaml +0 -16
- data/desc/ivars.yaml +0 -19
- data/desc/kernel.yaml +0 -15
- data/desc/mcopy.yaml +0 -11
- data/desc/mm.yaml +0 -15
- data/desc/not.yaml +0 -11
- data/desc/oo.yaml +0 -10
- data/desc/os.yaml +0 -19
- data/desc/qq.yaml +0 -11
- data/desc/regexp_to_proc.yaml +0 -12
- data/desc/regexp_visualize.yaml +0 -23
- data/desc/ruby_version.yaml +0 -28
- data/desc/sandbox.yaml +0 -13
- data/desc/square_brackets_for.yaml +0 -22
- data/desc/string.yaml +0 -22
- data/desc/tap.yaml +0 -17
- data/desc/unary.yaml +0 -15
- data/desc/union.yaml +0 -10
- data/doc/zucker_doc.html +0 -3042
- data/lib/zucker/aliases.rb +0 -52
- data/lib/zucker/array.rb +0 -15
- data/lib/zucker/array_to_proc.rb +0 -19
- data/lib/zucker/binding.rb +0 -35
- data/lib/zucker/case.rb +0 -14
- data/lib/zucker/cc.rb +0 -31
- data/lib/zucker/class_to_proc.rb +0 -13
- data/lib/zucker/control.rb +0 -4
- data/lib/zucker/dd.rb +0 -24
- data/lib/zucker/debug.rb +0 -4
- data/lib/zucker/default.rb +0 -4
- data/lib/zucker/engine.rb +0 -70
- data/lib/zucker/enumerable.rb +0 -15
- data/lib/zucker/env.rb +0 -4
- data/lib/zucker/extensions.rb +0 -4
- data/lib/zucker/file.rb +0 -28
- data/lib/zucker/hash.rb +0 -28
- data/lib/zucker/hash_to_proc.rb +0 -17
- data/lib/zucker/info.rb +0 -193
- data/lib/zucker/ivars.rb +0 -29
- data/lib/zucker/kernel.rb +0 -42
- data/lib/zucker/mcopy.rb +0 -11
- data/lib/zucker/mm.rb +0 -41
- data/lib/zucker/not.rb +0 -20
- data/lib/zucker/object.rb +0 -4
- data/lib/zucker/oo.rb +0 -18
- data/lib/zucker/os.rb +0 -55
- data/lib/zucker/qq.rb +0 -13
- data/lib/zucker/regexp_to_proc.rb +0 -13
- data/lib/zucker/regexp_visualize.rb +0 -31
- data/lib/zucker/ruby_version.rb +0 -120
- data/lib/zucker/sandbox.rb +0 -17
- data/lib/zucker/shortcuts.rb +0 -4
- data/lib/zucker/string.rb +0 -55
- data/lib/zucker/to_proc.rb +0 -4
- data/lib/zucker/unary.rb +0 -25
- data/lib/zucker/union.rb +0 -17
- data/spec/aliases_spec.rb +0 -13
- data/spec/array_spec.rb +0 -16
- data/spec/array_to_proc_spec.rb +0 -12
- data/spec/binding_spec.rb +0 -6
- data/spec/case_spec.rb +0 -15
- data/spec/cc_spec.rb +0 -6
- data/spec/class_to_proc_spec.rb +0 -9
- data/spec/dd_spec.rb +0 -37
- data/spec/engine_spec.rb +0 -11
- data/spec/enumerable_spec.rb +0 -8
- data/spec/file_spec.rb +0 -46
- data/spec/hash_spec.rb +0 -25
- data/spec/hash_to_proc_spec.rb +0 -12
- data/spec/info_spec.rb +0 -8
- data/spec/ivars_spec.rb +0 -20
- data/spec/kernel_spec.rb +0 -42
- data/spec/mm_spec.rb +0 -6
- data/spec/not_spec.rb +0 -10
- data/spec/oo_spec.rb +0 -6
- data/spec/os_spec.rb +0 -37
- data/spec/qq_spec.rb +0 -19
- data/spec/regexp_to_proc_spec.rb +0 -9
- data/spec/regexp_visualize_spec.rb +0 -38
- data/spec/ruby_version_spec.rb +0 -55
- data/spec/sandbox_spec.rb +0 -14
- data/spec/string_spec.rb +0 -65
data/lib/zucker/to_proc.rb
DELETED
data/lib/zucker/unary.rb
DELETED
data/lib/zucker/union.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'zucker'
|
2
|
-
module Zucker Union = true end
|
3
|
-
|
4
|
-
class Regexp
|
5
|
-
def |(arg)
|
6
|
-
Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class String
|
11
|
-
def |(arg)
|
12
|
-
Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# J-_-L
|
17
|
-
|
data/spec/aliases_spec.rb
DELETED
data/spec/array_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
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#chrs' do
|
12
|
-
it 'should convert the array to a string, using each element as ord value for the char' do
|
13
|
-
[72, 97, 108, 108, 111].chrs.should == 'Hallo'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
data/spec/array_to_proc_spec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
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/binding_spec.rb
DELETED
data/spec/case_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
if defined? BasicObject # 1.9 only
|
2
|
-
require 'zucker/case'
|
3
|
-
|
4
|
-
describe 'String#to_camel' do
|
5
|
-
it 'should turn a snake_cased string to CamelCase' do
|
6
|
-
'was_snake_case'.to_camel.should == 'WasSnakeCase'
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'String#to_snake' do
|
11
|
-
it 'should turn a CamelCased string to snake_case' do
|
12
|
-
'WasCamelCase'.to_snake.should == 'was_camel_case'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/spec/cc_spec.rb
DELETED
data/spec/class_to_proc_spec.rb
DELETED
data/spec/dd_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
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/engine_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
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/enumerable_spec.rb
DELETED
data/spec/file_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'zucker/file'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
describe 'File.gsub' do
|
5
|
-
let :random_filename do
|
6
|
-
'test_' + (0..20).map{|e| [*'a'..'z'].send RUBY_VERSION > '1.9' ? :sample : :choice }*''
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should read filename in arg1, substitute every key in the arg2 with its value and save the file' do
|
10
|
-
File.open(random_filename,'w'){ |file|
|
11
|
-
file.print 'should read filename in arg1, substitute every key in the arg2 with its value and save the file'
|
12
|
-
}
|
13
|
-
File.gsub random_filename,
|
14
|
-
/read/ => 'write',
|
15
|
-
/\d+/ => proc{|m| (m.to_i+1).to_s }
|
16
|
-
|
17
|
-
File.read(random_filename).should ==
|
18
|
-
'should write filename in arg2, substitute every key in the arg3 with its value and save the file'
|
19
|
-
|
20
|
-
FileUtils.rm random_filename
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'File.delete!' do
|
25
|
-
let :random_filename do
|
26
|
-
'test_' + (0..20).map{|e| [*'a'..'z'].send RUBY_VERSION > '1.9' ? :sample : :choice }*''
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should delete the filename given as argument if it exists + return non-nil' do
|
30
|
-
FileUtils.touch random_filename
|
31
|
-
res = false
|
32
|
-
proc do
|
33
|
-
res = File.delete! random_filename
|
34
|
-
end.should_not raise_exception
|
35
|
-
res.should be_true
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should do nothing if the filename given as argument does not exist + return nil' do
|
39
|
-
res = false
|
40
|
-
proc do
|
41
|
-
res = File.delete! random_filename
|
42
|
-
end.should_not raise_exception
|
43
|
-
res.should be_false
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
data/spec/hash_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
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
|
-
|
data/spec/hash_to_proc_spec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
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
DELETED
data/spec/ivars_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
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
DELETED
@@ -1,42 +0,0 @@
|
|
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 or RIPL' do; end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe 'ignore_sigint!' do
|
34
|
-
it 'should catch ctrl+c signals' do; end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'ignore_sigquit!' do
|
38
|
-
it 'should catch ctrl+\ signals' do; end
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
# J-_-L
|
data/spec/mm_spec.rb
DELETED
data/spec/not_spec.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
if defined? BasicObject # 1.9 only
|
2
|
-
require 'zucker/not'
|
3
|
-
|
4
|
-
describe 'Object#not' do
|
5
|
-
it "should return an object on which all methods are redirected to it's receiver object, but return an inverted boolean" do
|
6
|
-
[1,2,3].not.empty?.should == true
|
7
|
-
nil.not.nil?.should == false
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
data/spec/oo_spec.rb
DELETED
data/spec/os_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
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
|
-
|
data/spec/qq_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'zucker/qq'
|
2
|
-
|
3
|
-
describe 'q' do
|
4
|
-
|
5
|
-
it 'should output the same as p for a single arg' do
|
6
|
-
capture_stdout{p /some object/}.should ==
|
7
|
-
capture_stdout{q /some object/}
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should output the same as p but for multiple args one one line, values separated by two spaces" do
|
11
|
-
capture_stdout do
|
12
|
-
q 1, "1", 2..5, [], {:hallo => :du}, nil, true
|
13
|
-
end.chop.should ==
|
14
|
-
capture_stdout do
|
15
|
-
p 1, "1", 2..5, [], {:hallo => :du}, nil, true
|
16
|
-
end.chop.gsub( "\n", ' ' )
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|