zucker 13.1 → 100.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +17 -2
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +22 -0
  5. data/Rakefile +17 -58
  6. data/doc/{zucker_doc.rb → create_documentation.rb} +67 -129
  7. data/doc/zucker.html +1774 -0
  8. data/lib/zucker.rb +12 -42
  9. data/lib/zucker/alias_for.rb +9 -16
  10. data/lib/zucker/all.rb +0 -2
  11. data/lib/zucker/array_op.rb +15 -0
  12. data/lib/zucker/blank.rb +39 -21
  13. data/lib/zucker/camel_snake.rb +15 -0
  14. data/lib/zucker/constantize.rb +29 -0
  15. data/lib/zucker/dir_extras.rb +20 -0
  16. data/lib/zucker/egonil.rb +13 -24
  17. data/lib/zucker/file_extras.rb +33 -0
  18. data/lib/zucker/hash_extras.rb +11 -0
  19. data/lib/zucker/hash_op.rb +28 -0
  20. data/lib/zucker/instance_variables_from.rb +34 -0
  21. data/lib/zucker/iterate.rb +24 -21
  22. data/lib/zucker/marshal_copy.rb +11 -0
  23. data/lib/zucker/mash.rb +22 -0
  24. data/lib/zucker/ords.rb +17 -0
  25. data/lib/zucker/regexp_union.rb +17 -0
  26. data/lib/zucker/square_brackets_for.rb +12 -15
  27. data/lib/zucker/string_extras.rb +15 -0
  28. data/lib/zucker/string_op.rb +20 -0
  29. data/lib/zucker/tap.rb +13 -8
  30. data/lib/zucker/unary_conversion.rb +25 -0
  31. data/spec/alias_for_spec.rb +11 -73
  32. data/spec/array_op_spec.rb +17 -0
  33. data/spec/blank_spec.rb +2 -0
  34. data/spec/camel_snake_spec.rb +15 -0
  35. data/spec/constantize_spec.rb +33 -0
  36. data/spec/dir_extras_spec.rb +32 -0
  37. data/spec/egonil_spec.rb +1 -0
  38. data/spec/file_extras_spec.rb +57 -0
  39. data/spec/hash_extras_spec.rb +11 -0
  40. data/spec/hash_op_spec.rb +28 -0
  41. data/spec/instance_variables_from_spec.rb +24 -0
  42. data/spec/iterate_spec.rb +2 -0
  43. data/spec/{mcopy_spec.rb → marshal_copy_spec.rb} +5 -3
  44. data/spec/mash_spec.rb +17 -0
  45. data/spec/ords_spec.rb +15 -0
  46. data/spec/{union_spec.rb → regexp_union_spec.rb} +4 -2
  47. data/spec/square_brackets_for_spec.rb +4 -12
  48. data/spec/string_extras_spec.rb +20 -0
  49. data/spec/string_op_spec.rb +22 -0
  50. data/spec/tap_spec.rb +2 -0
  51. data/spec/{unary_spec.rb → unary_conversion_spec.rb} +4 -2
  52. data/zucker.gemspec +8 -18
  53. metadata +75 -147
  54. data/.gemtest +0 -0
  55. data/README +0 -7
  56. data/desc/alias_for.yaml +0 -17
  57. data/desc/aliases.yaml +0 -18
  58. data/desc/array.yaml +0 -11
  59. data/desc/array_to_proc.yaml +0 -16
  60. data/desc/binding.yaml +0 -22
  61. data/desc/blank.yaml +0 -11
  62. data/desc/case.yaml +0 -9
  63. data/desc/cc.yaml +0 -10
  64. data/desc/class_to_proc.yaml +0 -11
  65. data/desc/dd.yaml +0 -23
  66. data/desc/egonil.yaml +0 -15
  67. data/desc/engine.yaml +0 -15
  68. data/desc/enumerable.yaml +0 -10
  69. data/desc/file.yaml +0 -14
  70. data/desc/hash.yaml +0 -14
  71. data/desc/hash_to_proc.yaml +0 -10
  72. data/desc/info.yaml +0 -20
  73. data/desc/iterate.yaml +0 -16
  74. data/desc/ivars.yaml +0 -19
  75. data/desc/kernel.yaml +0 -15
  76. data/desc/mcopy.yaml +0 -11
  77. data/desc/mm.yaml +0 -15
  78. data/desc/not.yaml +0 -11
  79. data/desc/oo.yaml +0 -10
  80. data/desc/os.yaml +0 -19
  81. data/desc/qq.yaml +0 -11
  82. data/desc/regexp_to_proc.yaml +0 -12
  83. data/desc/regexp_visualize.yaml +0 -23
  84. data/desc/ruby_version.yaml +0 -28
  85. data/desc/sandbox.yaml +0 -13
  86. data/desc/square_brackets_for.yaml +0 -22
  87. data/desc/string.yaml +0 -22
  88. data/desc/tap.yaml +0 -17
  89. data/desc/unary.yaml +0 -15
  90. data/desc/union.yaml +0 -10
  91. data/doc/zucker_doc.html +0 -3042
  92. data/lib/zucker/aliases.rb +0 -52
  93. data/lib/zucker/array.rb +0 -15
  94. data/lib/zucker/array_to_proc.rb +0 -19
  95. data/lib/zucker/binding.rb +0 -35
  96. data/lib/zucker/case.rb +0 -14
  97. data/lib/zucker/cc.rb +0 -31
  98. data/lib/zucker/class_to_proc.rb +0 -13
  99. data/lib/zucker/control.rb +0 -4
  100. data/lib/zucker/dd.rb +0 -24
  101. data/lib/zucker/debug.rb +0 -4
  102. data/lib/zucker/default.rb +0 -4
  103. data/lib/zucker/engine.rb +0 -70
  104. data/lib/zucker/enumerable.rb +0 -15
  105. data/lib/zucker/env.rb +0 -4
  106. data/lib/zucker/extensions.rb +0 -4
  107. data/lib/zucker/file.rb +0 -28
  108. data/lib/zucker/hash.rb +0 -28
  109. data/lib/zucker/hash_to_proc.rb +0 -17
  110. data/lib/zucker/info.rb +0 -193
  111. data/lib/zucker/ivars.rb +0 -29
  112. data/lib/zucker/kernel.rb +0 -42
  113. data/lib/zucker/mcopy.rb +0 -11
  114. data/lib/zucker/mm.rb +0 -41
  115. data/lib/zucker/not.rb +0 -20
  116. data/lib/zucker/object.rb +0 -4
  117. data/lib/zucker/oo.rb +0 -18
  118. data/lib/zucker/os.rb +0 -55
  119. data/lib/zucker/qq.rb +0 -13
  120. data/lib/zucker/regexp_to_proc.rb +0 -13
  121. data/lib/zucker/regexp_visualize.rb +0 -31
  122. data/lib/zucker/ruby_version.rb +0 -120
  123. data/lib/zucker/sandbox.rb +0 -17
  124. data/lib/zucker/shortcuts.rb +0 -4
  125. data/lib/zucker/string.rb +0 -55
  126. data/lib/zucker/to_proc.rb +0 -4
  127. data/lib/zucker/unary.rb +0 -25
  128. data/lib/zucker/union.rb +0 -17
  129. data/spec/aliases_spec.rb +0 -13
  130. data/spec/array_spec.rb +0 -16
  131. data/spec/array_to_proc_spec.rb +0 -12
  132. data/spec/binding_spec.rb +0 -6
  133. data/spec/case_spec.rb +0 -15
  134. data/spec/cc_spec.rb +0 -6
  135. data/spec/class_to_proc_spec.rb +0 -9
  136. data/spec/dd_spec.rb +0 -37
  137. data/spec/engine_spec.rb +0 -11
  138. data/spec/enumerable_spec.rb +0 -8
  139. data/spec/file_spec.rb +0 -46
  140. data/spec/hash_spec.rb +0 -25
  141. data/spec/hash_to_proc_spec.rb +0 -12
  142. data/spec/info_spec.rb +0 -8
  143. data/spec/ivars_spec.rb +0 -20
  144. data/spec/kernel_spec.rb +0 -42
  145. data/spec/mm_spec.rb +0 -6
  146. data/spec/not_spec.rb +0 -10
  147. data/spec/oo_spec.rb +0 -6
  148. data/spec/os_spec.rb +0 -37
  149. data/spec/qq_spec.rb +0 -19
  150. data/spec/regexp_to_proc_spec.rb +0 -9
  151. data/spec/regexp_visualize_spec.rb +0 -38
  152. data/spec/ruby_version_spec.rb +0 -55
  153. data/spec/sandbox_spec.rb +0 -14
  154. data/spec/string_spec.rb +0 -65
@@ -1,52 +0,0 @@
1
- require 'zucker'
2
- module Zucker Aliases = true end
3
-
4
- class Object
5
- alias is_an? is_a? # thanks to utility_belt
6
- end
7
-
8
- module Enumerable
9
- alias with zip
10
- alias % zip
11
- end
12
-
13
- class Array
14
- alias ** product
15
- alias contains? include?
16
- end
17
-
18
- class String
19
- alias contains? include?
20
- end
21
-
22
- class Hash
23
- alias + merge
24
- end
25
-
26
- class Binding
27
- #alias [] eval
28
- def [](expr)
29
- self.eval "#{expr}"
30
- end
31
- end
32
-
33
- class << File
34
- alias filename basename # thanks rdp :)
35
- end
36
-
37
- class << Dir
38
- def join(*args)
39
- File.join(*args)
40
- end
41
-
42
- def split(*args)
43
- File.split(*args)
44
- end
45
- end
46
-
47
- # constants - who would use these in real-world code for other things?
48
- Infinity = 1.0 / 0.0 # or 2*Float::MAX or Float::INFINITY
49
- NaN = 0.0 / 0.0
50
-
51
- # J-_-L
52
-
data/lib/zucker/array.rb DELETED
@@ -1,15 +0,0 @@
1
- require 'zucker'
2
- module Zucker Array = true end
3
-
4
- class Array
5
- def ^(other)
6
- (self - other) + (other - self)
7
- end
8
-
9
- def chrs
10
- self.pack 'C*'
11
- end
12
- end
13
-
14
- # J-_-L
15
-
@@ -1,19 +0,0 @@
1
- require 'zucker'
2
- module Zucker ArrayToProc = true end
3
-
4
- class Array
5
- def to_proc
6
- Proc.new{ |obj|
7
- if self.first.is_a? Array
8
- self.inject(obj){ |result, nested_array|
9
- nested_array.to_proc.call result
10
- }
11
- else
12
- obj.send(*self)
13
- end
14
- }
15
- end
16
- end
17
-
18
- # J-_-L
19
-
@@ -1,35 +0,0 @@
1
- require 'zucker'
2
- module Zucker Binding = true end
3
-
4
- unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
5
- class Binding
6
- def variables
7
- put_vars = lambda { |array|
8
- if array.empty?
9
- ' - none'
10
- else
11
- array.map{|e|
12
- val = (self.eval "#{e}").inspect
13
- " - #{e}: #{ val }"
14
- }.join "\n"
15
- end
16
- }
17
-
18
- puts "#{self.to_s}
19
- local variables
20
- #{ put_vars[ self.eval 'local_variables' ] }
21
- (instance variables)
22
- #{ put_vars[ self.eval 'instance_variables' ] }
23
- self
24
- - #{self.eval 'self'}
25
- block_given?
26
- - #{self.eval 'block_given?'}"
27
-
28
- end
29
-
30
- alias vars variables
31
- end
32
- end
33
-
34
- # J-_-L
35
-
data/lib/zucker/case.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'zucker'
2
- module Zucker Case = true end
3
-
4
- class String
5
- def to_snake
6
- gsub(/(?<!^)[A-Z]/) do "_#$&" end.downcase
7
- end
8
-
9
- def to_camel
10
- gsub(/(?:^|_)([a-z])/) do $1.upcase end
11
- end
12
- end
13
-
14
- # J-_-L
data/lib/zucker/cc.rb DELETED
@@ -1,31 +0,0 @@
1
- require 'zucker'
2
- module Zucker Cc = true end
3
-
4
- module Kernel
5
- private
6
-
7
- def c(show_irb = false)
8
- method_stack = caller.reverse.map{ |m|
9
- m.rindex( /:\d+(:in `(.*)')?$/ )
10
- $2
11
- }.compact
12
-
13
- if !show_irb
14
- if a = method_stack.index( 'irb_binding' )
15
- method_stack = [ method_stack[0], '(irb)', *method_stack[a+1..-1] ]
16
- elsif a = method_stack[1..-1].index( '<main>' )
17
- method_stack = [ method_stack[0], '(ripl)', *method_stack[a+2..-1] ]
18
- end
19
- end
20
-
21
- # puts method_stack.map.with_index{ |m, i|
22
- method_stack.each_with_index{ |m, i|
23
- puts " "*i + m
24
- }
25
- nil
26
- end
27
-
28
- alias cc c
29
- end
30
-
31
- # J-_-L
@@ -1,13 +0,0 @@
1
- require 'zucker'
2
- module Zucker ClassToProc = true end
3
-
4
- class Class
5
- def to_proc
6
- Proc.new do |*args|
7
- self.new(*args)
8
- end
9
- end
10
- end
11
-
12
- # J-_-L
13
-
@@ -1,4 +0,0 @@
1
- require 'zucker'
2
- Zucker.require_this __FILE__
3
-
4
- # J-_-L
data/lib/zucker/dd.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'zucker'
2
- module Zucker Dd = true end
3
-
4
- module Kernel
5
- def d(*args, &block)
6
- if args.empty?
7
- tap{
8
- if block_given?
9
- puts yield self
10
- else
11
- puts self.inspect
12
- end
13
- }
14
- else
15
- raise ArgumentError, ".d - The parser thought that the code after .d are method arguments... Please don't put a space after d or use .d() or .d{} in this case!"
16
- # eval ...
17
- end
18
- end
19
-
20
- alias dd d
21
- end
22
-
23
- # J-_-L
24
-
data/lib/zucker/debug.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'zucker'
2
- Zucker.require_this __FILE__
3
-
4
- # J-_-L
@@ -1,4 +0,0 @@
1
- require 'zucker'
2
- Zucker.require_all
3
-
4
- # J-_-L
data/lib/zucker/engine.rb DELETED
@@ -1,70 +0,0 @@
1
- require 'zucker'
2
- module Zucker Engine = true end
3
-
4
- module RubyEngine
5
- # try to guess the interpreter
6
- @interpreter = case
7
- when RUBY_PLATFORM == 'parrot'
8
- 'cardinal'
9
- when Object.const_defined?(:RUBY_ENGINE)
10
- if RUBY_ENGINE == 'ruby'
11
- if RUBY_DESCRIPTION =~ /Enterprise/
12
- 'ree'
13
- else
14
- 'mri'
15
- end
16
- else
17
- RUBY_ENGINE.to_s # jruby, rbx, ironruby, macruby, etc.
18
- end
19
- else # probably 1.8
20
- 'mri'
21
- end
22
-
23
- class << self
24
- def is?(what)
25
- what === @interpreter
26
- end
27
- alias is is?
28
-
29
- def to_s
30
- @interpreter.to_s
31
- end
32
- alias inspect to_s
33
-
34
- # ask methods
35
-
36
- def mri?
37
- RubyEngine.is? 'mri'
38
- end
39
- alias official_ruby? mri?
40
- alias ruby? mri?
41
-
42
- def jruby?
43
- RubyEngine.is? 'jruby'
44
- end
45
- alias java? jruby?
46
-
47
- def rubinius?
48
- RubyEngine.is? 'rbx'
49
- end
50
- alias rbx? rubinius?
51
-
52
- def ree?
53
- RubyEngine.is? 'ree'
54
- end
55
- alias enterprise? ree?
56
-
57
- def ironruby?
58
- RubyEngine.is? 'ironruby'
59
- end
60
- alias iron_ruby? ironruby?
61
-
62
- def cardinal?
63
- RubyEngine.is? 'cardinal'
64
- end
65
- alias parrot? cardinal?
66
- alias perl? cardinal?
67
- end
68
- end
69
-
70
- # J-_-L
@@ -1,15 +0,0 @@
1
- require 'zucker'
2
- module Zucker Enumerable = true end
3
-
4
- module Enumerable
5
- def mash
6
- ret = {}
7
- each{ |kv|
8
- ret.store( *(yield(kv)[0,2]) )
9
- }
10
- ret
11
- end
12
- end
13
-
14
- # J-_-L
15
-
data/lib/zucker/env.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'zucker'
2
- Zucker.require_this __FILE__
3
-
4
- # J-_-L
@@ -1,4 +0,0 @@
1
- require 'zucker'
2
- Zucker.require_this __FILE__
3
-
4
- # J-_-L
data/lib/zucker/file.rb DELETED
@@ -1,28 +0,0 @@
1
- require 'zucker'
2
- module Zucker File = true end
3
-
4
- class << File
5
- def gsub(filename, regex_hash)
6
- data = File.read filename
7
- File.open(filename,'w'){ |file|
8
- regex_hash.each{ |regex, new_string|
9
- regex = regex.to_s unless regex.is_a? Regexp
10
-
11
- if new_string.is_a? Proc
12
- data.gsub! regex, &new_string
13
- else
14
- data.gsub! regex, new_string
15
- end
16
- }
17
- file.print data
18
- }
19
- end
20
-
21
- def delete! filename
22
- return nil if !File.exist?(filename)
23
- File.delete filename
24
- end
25
- end
26
-
27
- # J-_-L
28
-
data/lib/zucker/hash.rb DELETED
@@ -1,28 +0,0 @@
1
- require 'zucker'
2
- module Zucker Hash = true end
3
-
4
- class Hash
5
- def self.zip(keys,values)
6
- Hash[ *keys.zip( values ).flatten ]
7
- end
8
-
9
- def <<(other)
10
- case
11
- when other.is_a?(Hash)
12
- merge! other
13
- when other.is_a?(Enumerable) || other.respond_to?(:to_splat)
14
- merge! Hash[*other]
15
- else
16
- raise TypeError, 'can only append other Hashs and Enumerables (or Classes that implement to_splat)'
17
- end
18
- end
19
-
20
- def &(other)
21
- Hash[ *select{ |k,v|
22
- other[k] == v
23
- }.flatten ]
24
- end
25
- end
26
-
27
- # J-_-L
28
-
@@ -1,17 +0,0 @@
1
- require 'zucker'
2
- module Zucker HashToProc = true end
3
-
4
- class Hash
5
- def to_proc
6
- Proc.new{ |obj|
7
- if self.member? obj
8
- self[obj].to_proc.call obj
9
- else
10
- obj
11
- end
12
- }
13
- end
14
- end
15
-
16
- # J-_-L
17
-
data/lib/zucker/info.rb DELETED
@@ -1,193 +0,0 @@
1
- require 'zucker'
2
- require 'rbconfig'
3
- require 'etc'
4
- module Zucker Info = true end
5
-
6
- module Info
7
- class << self
8
- # hash like access
9
- def [](what)
10
- send what
11
- end
12
-
13
- # list available info methods
14
- def list
15
- singleton_methods - [:[], :list, '[]', 'list']
16
- end
17
- end
18
-
19
- module_function
20
-
21
- # input
22
- def last_input_file
23
- $FILENAME
24
- end
25
-
26
- def last_input_line_number
27
- $.
28
- end
29
-
30
- def last_input
31
- $_
32
- end
33
-
34
- # program
35
- def program_name
36
- $0
37
- end
38
-
39
- def program_arguments
40
- $:
41
- end
42
-
43
- def loaded_programs
44
- $"
45
- end
46
-
47
- def program_data
48
- ::DATA
49
- end
50
-
51
- def child_program_status
52
- $CHILD_STATUS
53
- end
54
-
55
- # system info
56
- def environment
57
- ::ENV
58
- end
59
- alias env environment
60
-
61
- def working_directory
62
- Dir.pwd
63
- end
64
-
65
- def platform
66
- ::RUBY_PLATFORM
67
- end
68
-
69
- def os
70
- RbConfig::CONFIG['host_os']
71
- end
72
-
73
- def process_id
74
- $$
75
- end
76
-
77
- def load_path
78
- $:
79
- end
80
-
81
- # user
82
- def user_login
83
- Etc.getlogin
84
- end
85
-
86
- def user_name
87
- Etc.getpwnam(user_login).gecos.split(',')[0]
88
- end
89
-
90
- # current
91
-
92
- def current_file # __FILE__
93
- return $` if caller[0].rindex(/:\d+(:in `.*')?$/)
94
- end
95
-
96
- def current_file_directory
97
- if current_file[0,1] == '(' && current_file[-1,1] == ')'
98
- current_file
99
- else
100
- File.dirname(current_file)
101
- end
102
- end
103
-
104
- def current_line # __LINE__
105
- return $1.to_i if caller[0].rindex( /:(\d+)(:in `.*')?$/ )
106
- end
107
-
108
- def current_method # __method__ (except aliases)
109
- return $1.to_sym if caller(1)[0].rindex( /\`([^\']+)\'/ )
110
- end
111
-
112
- def current_callstack
113
- caller
114
- end
115
-
116
- # dealing with strings
117
- def gets_separator
118
- $/
119
- end
120
-
121
- def join_separator
122
- $,
123
- end
124
-
125
- def print_separator
126
- $,
127
- end
128
-
129
- def split_separator
130
- $;
131
- end
132
-
133
- # misc
134
- def security_level
135
- $SAFE
136
- end
137
-
138
- def warnings_activated?
139
- $VERBOSE
140
- end
141
-
142
- def debug_activated?
143
- $DEBUG
144
- end
145
-
146
- def last_exception
147
- $!
148
- end
149
-
150
- # defined objects
151
- def global_variables
152
- Object.send :global_variables
153
- end
154
-
155
- def global_constants
156
- Object.constants
157
- end
158
-
159
- # encoding (1.9)
160
- #def source_encoding
161
- # __ENCODING__
162
- #end
163
-
164
- def external_encoding
165
- Encoding.default_external
166
- end
167
-
168
- def internal_encoding
169
- Encoding.default_internal
170
- end
171
-
172
- # ruby version info
173
- def ruby_version # also see the RubyVersion cube
174
- ::RUBY_VERSION
175
- end
176
-
177
- def ruby_patchlevel
178
- ::RUBY_PATCHLEVEL
179
- end
180
-
181
- def ruby_description
182
- ::RUBY_DESCRIPTION
183
- end
184
-
185
- def ruby_release_date
186
- ::RUBY_RELEASE_DATE
187
- end
188
-
189
- def ruby_engine # warning! not support by every implementation. It's saver to use the RubyEngine cube
190
- ::RUBY_ENGINE
191
- end
192
- end
193
-