zucker 0.9

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.
Files changed (88) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +4 -0
  3. data/Rakefile +23 -0
  4. data/lib/zucker.rb +10 -0
  5. data/lib/zucker/1/D.rb +19 -0
  6. data/lib/zucker/1/aliases.rb +28 -0
  7. data/lib/zucker/1/all.rb +6 -0
  8. data/lib/zucker/1/array.rb +17 -0
  9. data/lib/zucker/1/array2proc.rb +10 -0
  10. data/lib/zucker/1/binding.rb +25 -0
  11. data/lib/zucker/1/blank.rb +26 -0
  12. data/lib/zucker/1/class2proc.rb +10 -0
  13. data/lib/zucker/1/debug.rb +4 -0
  14. data/lib/zucker/1/default.rb +25 -0
  15. data/lib/zucker/1/descriptions/D.yaml +25 -0
  16. data/lib/zucker/1/descriptions/aliases.yaml +18 -0
  17. data/lib/zucker/1/descriptions/array.yaml +16 -0
  18. data/lib/zucker/1/descriptions/array2proc.yaml +15 -0
  19. data/lib/zucker/1/descriptions/binding.yaml +12 -0
  20. data/lib/zucker/1/descriptions/blank.yaml +14 -0
  21. data/lib/zucker/1/descriptions/class2proc.yaml +15 -0
  22. data/lib/zucker/1/descriptions/egonil.yaml +20 -0
  23. data/lib/zucker/1/descriptions/enumerable.yaml +13 -0
  24. data/lib/zucker/1/descriptions/hash.yaml +14 -0
  25. data/lib/zucker/1/descriptions/hash2proc.yaml +13 -0
  26. data/lib/zucker/1/descriptions/iterate.yaml +19 -0
  27. data/lib/zucker/1/descriptions/ivars.yaml +22 -0
  28. data/lib/zucker/1/descriptions/kernel.yaml +13 -0
  29. data/lib/zucker/1/descriptions/mcopy.yaml +14 -0
  30. data/lib/zucker/1/descriptions/mm.yaml +14 -0
  31. data/lib/zucker/1/descriptions/regexp2proc.yaml +15 -0
  32. data/lib/zucker/1/descriptions/sandbox.yaml +16 -0
  33. data/lib/zucker/1/descriptions/square_brackets_for.yaml +25 -0
  34. data/lib/zucker/1/descriptions/string.yaml +15 -0
  35. data/lib/zucker/1/descriptions/unary.yaml +15 -0
  36. data/lib/zucker/1/descriptions/union.yaml +11 -0
  37. data/lib/zucker/1/documentation/meta.yaml +4 -0
  38. data/lib/zucker/1/documentation/zucker_doc.html +1158 -0
  39. data/lib/zucker/1/documentation/zucker_doc.rb +369 -0
  40. data/lib/zucker/1/egonil.rb +14 -0
  41. data/lib/zucker/1/enumerable.rb +12 -0
  42. data/lib/zucker/1/hash.rb +19 -0
  43. data/lib/zucker/1/hash2proc.rb +12 -0
  44. data/lib/zucker/1/iterate.rb +23 -0
  45. data/lib/zucker/1/ivars.rb +26 -0
  46. data/lib/zucker/1/kernel.rb +20 -0
  47. data/lib/zucker/1/mcopy.rb +9 -0
  48. data/lib/zucker/1/mm.rb +31 -0
  49. data/lib/zucker/1/regexp2proc.rb +10 -0
  50. data/lib/zucker/1/sandbox.rb +15 -0
  51. data/lib/zucker/1/specification/D_spec.rb +27 -0
  52. data/lib/zucker/1/specification/aliases_spec.rb +34 -0
  53. data/lib/zucker/1/specification/array2proc_spec.rb +8 -0
  54. data/lib/zucker/1/specification/array_spec.rb +23 -0
  55. data/lib/zucker/1/specification/binding_spec.rb +6 -0
  56. data/lib/zucker/1/specification/blank_spec.rb +20 -0
  57. data/lib/zucker/1/specification/class2proc_spec.rb +9 -0
  58. data/lib/zucker/1/specification/egonil_spec.rb +30 -0
  59. data/lib/zucker/1/specification/enumerable_spec.rb +8 -0
  60. data/lib/zucker/1/specification/hash2proc_spec.rb +12 -0
  61. data/lib/zucker/1/specification/hash_spec.rb +10 -0
  62. data/lib/zucker/1/specification/iterate_spec.rb +54 -0
  63. data/lib/zucker/1/specification/ivars_spec.rb +20 -0
  64. data/lib/zucker/1/specification/kernel_spec.rb +34 -0
  65. data/lib/zucker/1/specification/mcopy_spec.rb +13 -0
  66. data/lib/zucker/1/specification/mm_spec.rb +6 -0
  67. data/lib/zucker/1/specification/regexp2proc_spec.rb +9 -0
  68. data/lib/zucker/1/specification/sandbox_spec.rb +7 -0
  69. data/lib/zucker/1/specification/square_brackets_for_spec.rb +59 -0
  70. data/lib/zucker/1/specification/string_spec.rb +29 -0
  71. data/lib/zucker/1/specification/unary_spec.rb +26 -0
  72. data/lib/zucker/1/specification/union_spec.rb +13 -0
  73. data/lib/zucker/1/square_brackets_for.rb +20 -0
  74. data/lib/zucker/1/string.rb +25 -0
  75. data/lib/zucker/1/unary.rb +22 -0
  76. data/lib/zucker/1/union.rb +14 -0
  77. data/lib/zucker/all.rb +2 -0
  78. data/lib/zucker/debug.rb +2 -0
  79. data/lib/zucker/default.rb +2 -0
  80. data/lib/zucker/edge/ideas/args.rb +22 -0
  81. data/lib/zucker/edge/ideas/args.yaml +19 -0
  82. data/lib/zucker/edge/ideas/args_spec.rb +19 -0
  83. data/lib/zucker/edge/ideas/clone_deep.rb +21 -0
  84. data/lib/zucker/edge/ideas/clone_deep_spec.rb +12 -0
  85. data/lib/zucker/edge/ideas/dclone.yaml +12 -0
  86. data/lib/zucker/edge/ideas/hash.rb +18 -0
  87. data/lib/zucker/edge/ideas/require_directory.rb +6 -0
  88. metadata +153 -0
@@ -0,0 +1,6 @@
1
+ require 'mm'
2
+
3
+ describe 'Object#method_list' do
4
+ it 'should display an ordered method list'
5
+ end
6
+
@@ -0,0 +1,9 @@
1
+ require 'regexp2proc'
2
+
3
+ describe 'Regexp#to_proc' do
4
+ it 'should match the regex' do
5
+ %w|just another string array|.map( &/[jy]/).should == ["j", nil, nil, "y"]
6
+ %w|just another string array|.select( &/[jy]/).should == ["just", "array"]
7
+ end
8
+ end
9
+
@@ -0,0 +1,7 @@
1
+ require 'sandbox'
2
+
3
+ describe 'sandbox' do
4
+ it 'should throw a SecurityError if bad commands are issued'
5
+ it 'should run the lambda passed as first parameter for errors, if it is given'
6
+ end
7
+
@@ -0,0 +1,59 @@
1
+ require 'square_brackets_for'
2
+
3
+ describe 'square_brackets_for' do
4
+
5
+ before do
6
+ class Klass
7
+ def initialize
8
+ @var = {
9
+ :a_key => 1,
10
+ :another_one => 2,
11
+ }
12
+ end
13
+
14
+ @eigenvar = {
15
+ :a_key => 99
16
+ }
17
+ end
18
+ end
19
+
20
+ it 'should define a [] getter (not a setter) for an instance var, if the second parameter is false' do
21
+
22
+ class Klass
23
+ square_brackets_for :var, nil
24
+ end
25
+
26
+ a = Klass.new
27
+ a[:a_key].should == 1
28
+
29
+ proc do
30
+ a[:this_is] = 'not possible'
31
+ end.should raise_exception NoMethodError
32
+ end
33
+
34
+ it 'should define [] and []= for accessing an instance variable' do
35
+
36
+ class Klass
37
+ square_brackets_for :var
38
+ end
39
+
40
+ a = Klass.new
41
+ a[:a_key].should == 1
42
+
43
+ a[:this_is] = 'useful'
44
+ a[:this_is].should == 'useful'
45
+ end
46
+
47
+ it 'should also work for class-instance variables' do
48
+
49
+ class Klass
50
+ class << Klass
51
+ square_brackets_for :eigenvar
52
+ end
53
+ end
54
+
55
+ Klass[:a_key].should == 99
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,29 @@
1
+ require 'string'
2
+
3
+ describe 'String#^' do
4
+ it 'should give C-like substring access to strings' do
5
+ string = 'Theoretische Informatik ist voll geil!'
6
+
7
+ (string|0).should == 'Theoretische Informatik ist voll geil!'
8
+ (string|1).should == 'heoretische Informatik ist voll geil!'
9
+ (string|13).should == 'Informatik ist voll geil!'
10
+ (string|-1).should == 'Theoretische Informatik ist voll geil'
11
+ (string|38).should == ''
12
+ (string|99).should == nil
13
+ end
14
+ end
15
+
16
+ describe 'String#lchomp' do
17
+ it 'should chomp on the left side' do
18
+ string = 'Theoretische Informatik ist voll geil!'
19
+ string.lchomp('T').should == 'heoretische Informatik ist voll geil!'
20
+ end
21
+ end
22
+
23
+ describe 'String#ords' do
24
+ it 'should unpack characters' do
25
+ string = 'Theoretische Informatik ist voll geil!'
26
+ string.ords.should == [84, 104, 101, 111, 114, 101, 116, 105, 115, 99, 104, 101, 32, 73, 110, 102, 111, 114, 109, 97, 116, 105, 107, 32, 105, 115, 116, 32, 118, 111, 108, 108, 32, 103, 101, 105, 108, 33]
27
+ end
28
+ end
29
+
@@ -0,0 +1,26 @@
1
+ require 'unary'
2
+
3
+ describe Symbol, '#+@' do
4
+ it 'should convert to_s' do
5
+ +(:matz) == 'matz' # () 1.8 bug
6
+ end
7
+ end
8
+
9
+ describe Symbol, '#-@' do
10
+ it 'should do nothing' do
11
+ -:matz == :matz
12
+ end
13
+ end
14
+
15
+ describe String, '#+@' do
16
+ it 'should do nothing' do
17
+ +'matz' == 'matz'
18
+ end
19
+ end
20
+
21
+ describe String, '#-@' do
22
+ it 'should convert to_sym' do
23
+ -'matz' == :matz
24
+ end
25
+ end
26
+
@@ -0,0 +1,13 @@
1
+ require 'union'
2
+
3
+ describe 'Regexp#|' do
4
+ it 'should create an Regexp.union of both operands' do
5
+ (/hallo/ | /\d+/ | /./).should ==
6
+ Regexp.union( Regexp.union(/hallo/, /\d+/), /./ )
7
+ end
8
+ end
9
+
10
+ describe 'String#|' do
11
+ it_should_behave_like 'Regexp#|'
12
+ end
13
+
@@ -0,0 +1,20 @@
1
+ def square_brackets_for(ivar, assignment = true)
2
+ # undef [] if respond_to? :[]
3
+ # undef []= if respond_to? :[]=
4
+
5
+ #instance_eval do
6
+ define_method :[] do |key|
7
+ (instance_variable_get :"@#{ivar}")[key]
8
+ end
9
+
10
+ if assignment
11
+ define_method :[]= do |key, value|
12
+ (instance_variable_get :"@#{ivar}")[key] = value
13
+ end
14
+ end
15
+ #end
16
+
17
+ end
18
+
19
+ # J-_-L
20
+
@@ -0,0 +1,25 @@
1
+ class String
2
+ def ^(pos)
3
+ pos = pos.to_i
4
+ if pos >= 0
5
+ self[pos..-1]
6
+ else
7
+ self[0...pos]
8
+ end
9
+ end
10
+
11
+ def lchomp(arg=$/)
12
+ self.reverse.chomp(arg).reverse
13
+ end
14
+
15
+ def lchomp!(arg=$/)
16
+ self.reverse.chomp!(arg).reverse
17
+ end
18
+
19
+ def ords
20
+ self.unpack 'C*'
21
+ end
22
+ end
23
+
24
+ # J-_-L
25
+
@@ -0,0 +1,22 @@
1
+ class String
2
+ def +@
3
+ self
4
+ end
5
+
6
+ def -@
7
+ to_sym
8
+ end
9
+ end
10
+
11
+ class Symbol
12
+ def +@
13
+ to_s
14
+ end
15
+
16
+ def -@
17
+ self
18
+ end
19
+ end
20
+
21
+ # J-_-L
22
+
@@ -0,0 +1,14 @@
1
+ class Regexp
2
+ def |(arg)
3
+ Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s
4
+ end
5
+ end
6
+
7
+ class String
8
+ def |(arg)
9
+ Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s
10
+ end
11
+ end
12
+
13
+ # J-_-L
14
+
@@ -0,0 +1,2 @@
1
+ require 'zucker/1/all'
2
+
@@ -0,0 +1,2 @@
1
+ require 'zucker/1/debug'
2
+
@@ -0,0 +1,2 @@
1
+ require 'zucker/1/default'
2
+
@@ -0,0 +1,22 @@
1
+ def arguments
2
+ mbinding = @@last_bindings[2]
3
+ margs = mbinding.eval "local_variables"
4
+ ret = {}
5
+
6
+ margs.each{ |arg|
7
+ ret[arg.to_sym] = mbinding.eval(arg)
8
+ }
9
+ ret
10
+ end
11
+ alias args arguments
12
+
13
+ #### EVIL ####
14
+ # set up binding tracer
15
+ @@last_bindings ||= []
16
+ set_trace_func lambda { |event, _, _, _, bind, _|
17
+ if event[/call/]
18
+ @@last_bindings.unshift bind
19
+ @@last_bindings.pop if @@last_bindings.size > 5
20
+ end
21
+ }
22
+
@@ -0,0 +1,19 @@
1
+ args:
2
+ summary: hallo
3
+ why: |
4
+ Often you just need to
5
+ for example, do you know this one:
6
+ ⇧def initialize(variable1, variable2)
7
+ @variable1, @variable2 = variable1, variable2
8
+ end⇧
9
+ methods:
10
+ arguments, args: "def a_method(a=1, b=2)\n arguments # => {a=>1, b=>2}\nend"
11
+ info:
12
+ - Not in default, because it uses ⇧Kernel#set_trace_var⇧ (which would)...
13
+ package: debug
14
+ versions:
15
+ - 1.9
16
+ - 1.8
17
+ authors:
18
+ - Jan Lelis
19
+
@@ -0,0 +1,19 @@
1
+ require 'args'
2
+
3
+ describe 'arguments' do
4
+ it 'should create a hash containing all arguments with its names' do
5
+
6
+ def ma(hallo = 5, baum = 7)
7
+ hallo = 9
8
+ arguments
9
+ end
10
+
11
+ def mb
12
+ arguments
13
+ end
14
+
15
+ ma(3).should == {:hallo => 3, :baum => 7}
16
+ mb.should == {}
17
+ end
18
+ end
19
+
@@ -0,0 +1,21 @@
1
+ class Object
2
+ def clone_deep
3
+ case self.class
4
+ when Array
5
+ self.map &:clone_deep
6
+ else
7
+ self.clone
8
+ end
9
+ end
10
+ alias :dclone :clone_deep
11
+
12
+ def dup_deep
13
+ if self.is_a? Array
14
+ self.map &:dup_deep
15
+ else
16
+ self.dup
17
+ end
18
+ end
19
+ alias :ddup :dup_deep
20
+ end
21
+
@@ -0,0 +1,12 @@
1
+ require 'clone_deep'
2
+
3
+ describe 'Array#clone_deep' do
4
+ it 'create a deep copy' do
5
+ a = [1,2,3,4,["Hallo",["Welt"],[]]]
6
+ b = a.clone_deep
7
+ b.should == a
8
+ b[5][3,1] = ''
9
+ b.should != a
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ dclone:
2
+ summary: Adds deep ⇧clon⇧/⇧dup⇧ methods
3
+ why: Sometimes you need real copies
4
+ methods:
5
+ Object#dclone: 123
6
+ package: default
7
+ versions:
8
+ - 1.9
9
+ - 1.8
10
+ authors:
11
+ - Jan Lelis
12
+
@@ -0,0 +1,18 @@
1
+
2
+ # File lib/core/facets/hash/op_and.rb, line 19
3
+ # def &(other)
4
+ # Hash[ *select{ |k,v|
5
+ # other[k] == v
6
+ # }.flatten ]
7
+ # end
8
+
9
+ # def ^(other)
10
+ # Hash[ *reject{ |k,v|
11
+ # other[k] == v
12
+ # }.flatten ]
13
+ # end
14
+
15
+ # def -(other)
16
+ #
17
+ # end
18
+
@@ -0,0 +1,6 @@
1
+ def require_directory(path)
2
+ Dir[File.join path, '*.rb'].each{ |filename|
3
+ require filename
4
+ }
5
+ end
6
+
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zucker
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ version: "0.9"
10
+ platform: ruby
11
+ authors:
12
+ - Jan Lelis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-05 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: mail@janlelis.de
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - MIT-LICENSE
31
+ - Rakefile
32
+ - README
33
+ - lib/zucker/default.rb
34
+ - lib/zucker/all.rb
35
+ - lib/zucker/1/default.rb
36
+ - lib/zucker/1/all.rb
37
+ - lib/zucker/1/string.rb
38
+ - lib/zucker/1/sandbox.rb
39
+ - lib/zucker/1/regexp2proc.rb
40
+ - lib/zucker/1/ivars.rb
41
+ - lib/zucker/1/class2proc.rb
42
+ - lib/zucker/1/enumerable.rb
43
+ - lib/zucker/1/documentation/meta.yaml
44
+ - lib/zucker/1/documentation/zucker_doc.html
45
+ - lib/zucker/1/documentation/zucker_doc.rb
46
+ - lib/zucker/1/unary.rb
47
+ - lib/zucker/1/hash.rb
48
+ - lib/zucker/1/hash2proc.rb
49
+ - lib/zucker/1/blank.rb
50
+ - lib/zucker/1/array2proc.rb
51
+ - lib/zucker/1/specification/hash2proc_spec.rb
52
+ - lib/zucker/1/specification/iterate_spec.rb
53
+ - lib/zucker/1/specification/D_spec.rb
54
+ - lib/zucker/1/specification/kernel_spec.rb
55
+ - lib/zucker/1/specification/union_spec.rb
56
+ - lib/zucker/1/specification/string_spec.rb
57
+ - lib/zucker/1/specification/class2proc_spec.rb
58
+ - lib/zucker/1/specification/unary_spec.rb
59
+ - lib/zucker/1/specification/egonil_spec.rb
60
+ - lib/zucker/1/specification/ivars_spec.rb
61
+ - lib/zucker/1/specification/sandbox_spec.rb
62
+ - lib/zucker/1/specification/hash_spec.rb
63
+ - lib/zucker/1/specification/array2proc_spec.rb
64
+ - lib/zucker/1/specification/binding_spec.rb
65
+ - lib/zucker/1/specification/mcopy_spec.rb
66
+ - lib/zucker/1/specification/aliases_spec.rb
67
+ - lib/zucker/1/specification/square_brackets_for_spec.rb
68
+ - lib/zucker/1/specification/enumerable_spec.rb
69
+ - lib/zucker/1/specification/blank_spec.rb
70
+ - lib/zucker/1/specification/mm_spec.rb
71
+ - lib/zucker/1/specification/array_spec.rb
72
+ - lib/zucker/1/specification/regexp2proc_spec.rb
73
+ - lib/zucker/1/array.rb
74
+ - lib/zucker/1/binding.rb
75
+ - lib/zucker/1/mm.rb
76
+ - lib/zucker/1/aliases.rb
77
+ - lib/zucker/1/iterate.rb
78
+ - lib/zucker/1/egonil.rb
79
+ - lib/zucker/1/mcopy.rb
80
+ - lib/zucker/1/descriptions/class2proc.yaml
81
+ - lib/zucker/1/descriptions/iterate.yaml
82
+ - lib/zucker/1/descriptions/unary.yaml
83
+ - lib/zucker/1/descriptions/ivars.yaml
84
+ - lib/zucker/1/descriptions/D.yaml
85
+ - lib/zucker/1/descriptions/array.yaml
86
+ - lib/zucker/1/descriptions/array2proc.yaml
87
+ - lib/zucker/1/descriptions/square_brackets_for.yaml
88
+ - lib/zucker/1/descriptions/mm.yaml
89
+ - lib/zucker/1/descriptions/regexp2proc.yaml
90
+ - lib/zucker/1/descriptions/mcopy.yaml
91
+ - lib/zucker/1/descriptions/hash2proc.yaml
92
+ - lib/zucker/1/descriptions/enumerable.yaml
93
+ - lib/zucker/1/descriptions/union.yaml
94
+ - lib/zucker/1/descriptions/kernel.yaml
95
+ - lib/zucker/1/descriptions/hash.yaml
96
+ - lib/zucker/1/descriptions/aliases.yaml
97
+ - lib/zucker/1/descriptions/sandbox.yaml
98
+ - lib/zucker/1/descriptions/blank.yaml
99
+ - lib/zucker/1/descriptions/string.yaml
100
+ - lib/zucker/1/descriptions/binding.yaml
101
+ - lib/zucker/1/descriptions/egonil.yaml
102
+ - lib/zucker/1/D.rb
103
+ - lib/zucker/1/square_brackets_for.rb
104
+ - lib/zucker/1/kernel.rb
105
+ - lib/zucker/1/debug.rb
106
+ - lib/zucker/1/union.rb
107
+ - lib/zucker/edge/ideas/dclone.yaml
108
+ - lib/zucker/edge/ideas/hash.rb
109
+ - lib/zucker/edge/ideas/require_directory.rb
110
+ - lib/zucker/edge/ideas/clone_deep_spec.rb
111
+ - lib/zucker/edge/ideas/args.yaml
112
+ - lib/zucker/edge/ideas/clone_deep.rb
113
+ - lib/zucker/edge/ideas/args.rb
114
+ - lib/zucker/edge/ideas/args_spec.rb
115
+ - lib/zucker/debug.rb
116
+ - lib/zucker.rb
117
+ has_rdoc: true
118
+ homepage: http://rubyzucker.info
119
+ licenses: []
120
+
121
+ post_install_message:
122
+ rdoc_options: []
123
+
124
+ require_paths:
125
+ - .
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ requirements: []
146
+
147
+ rubyforge_project:
148
+ rubygems_version: 1.3.7
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: Add more sugar to Ruby
152
+ test_files: []
153
+