zucker 4 → 5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +15 -1
- data/Rakefile +44 -0
- data/lib/zucker.rb +71 -10
- data/lib/zucker/1/D.rb +2 -0
- data/lib/zucker/1/aliases.rb +2 -0
- data/lib/zucker/1/all.rb +2 -0
- data/lib/zucker/1/array.rb +2 -0
- data/lib/zucker/1/array2proc.rb +2 -0
- data/lib/zucker/1/binding.rb +2 -0
- data/lib/zucker/1/blank.rb +2 -0
- data/lib/zucker/1/class2proc.rb +2 -0
- data/lib/zucker/1/debug.rb +2 -0
- data/lib/zucker/1/default.rb +2 -0
- data/lib/zucker/1/egonil.rb +2 -0
- data/lib/zucker/1/enumerable.rb +2 -0
- data/lib/zucker/1/hash.rb +2 -0
- data/lib/zucker/1/hash2proc.rb +2 -0
- data/lib/zucker/1/iterate.rb +2 -0
- data/lib/zucker/1/ivars.rb +2 -0
- data/lib/zucker/1/kernel.rb +2 -0
- data/lib/zucker/1/mcopy.rb +2 -0
- data/lib/zucker/1/mm.rb +2 -0
- data/lib/zucker/1/regexp2proc.rb +2 -0
- data/lib/zucker/1/sandbox.rb +2 -0
- data/lib/zucker/1/square_brackets_for.rb +2 -0
- data/lib/zucker/1/string.rb +2 -0
- data/lib/zucker/1/unary.rb +2 -0
- data/lib/zucker/1/union.rb +2 -0
- data/lib/zucker/2/D.rb +2 -0
- data/lib/zucker/2/aliases.rb +2 -0
- data/lib/zucker/2/all.rb +2 -0
- data/lib/zucker/2/array.rb +2 -0
- data/lib/zucker/2/array2proc.rb +2 -0
- data/lib/zucker/2/binding.rb +2 -0
- data/lib/zucker/2/blank.rb +2 -0
- data/lib/zucker/2/class2proc.rb +2 -0
- data/lib/zucker/2/debug.rb +2 -0
- data/lib/zucker/2/default.rb +2 -0
- data/lib/zucker/2/egonil.rb +2 -0
- data/lib/zucker/2/enumerable.rb +2 -0
- data/lib/zucker/2/hash.rb +2 -0
- data/lib/zucker/2/hash2proc.rb +2 -0
- data/lib/zucker/2/info.rb +2 -0
- data/lib/zucker/2/iterate.rb +2 -0
- data/lib/zucker/2/ivars.rb +2 -0
- data/lib/zucker/2/kernel.rb +2 -0
- data/lib/zucker/2/mcopy.rb +2 -0
- data/lib/zucker/2/mm.rb +2 -0
- data/lib/zucker/2/regexp2proc.rb +2 -0
- data/lib/zucker/2/sandbox.rb +2 -0
- data/lib/zucker/2/square_brackets_for.rb +2 -0
- data/lib/zucker/2/string.rb +2 -0
- data/lib/zucker/2/unary.rb +2 -0
- data/lib/zucker/2/union.rb +2 -0
- data/lib/zucker/3/D.rb +2 -0
- data/lib/zucker/3/alias_for.rb +2 -0
- data/lib/zucker/3/aliases.rb +2 -0
- data/lib/zucker/3/all.rb +2 -0
- data/lib/zucker/3/array.rb +2 -0
- data/lib/zucker/3/array2proc.rb +2 -0
- data/lib/zucker/3/binding.rb +2 -0
- data/lib/zucker/3/blank.rb +2 -0
- data/lib/zucker/3/class2proc.rb +2 -0
- data/lib/zucker/3/debug.rb +2 -0
- data/lib/zucker/3/default.rb +2 -0
- data/lib/zucker/3/egonil.rb +2 -0
- data/lib/zucker/3/enumerable.rb +2 -0
- data/lib/zucker/3/hash.rb +2 -0
- data/lib/zucker/3/hash2proc.rb +2 -0
- data/lib/zucker/3/info.rb +2 -0
- data/lib/zucker/3/iterate.rb +2 -0
- data/lib/zucker/3/ivars.rb +2 -0
- data/lib/zucker/3/kernel.rb +2 -0
- data/lib/zucker/3/mcopy.rb +2 -0
- data/lib/zucker/3/mm.rb +2 -0
- data/lib/zucker/3/not.rb +2 -0
- data/lib/zucker/3/regexp2proc.rb +2 -0
- data/lib/zucker/3/sandbox.rb +2 -0
- data/lib/zucker/3/square_brackets_for.rb +2 -0
- data/lib/zucker/3/string.rb +2 -0
- data/lib/zucker/3/tap.rb +2 -0
- data/lib/zucker/3/unary.rb +2 -0
- data/lib/zucker/3/union.rb +2 -0
- data/lib/zucker/{D.rb → 4/D.rb} +2 -0
- data/lib/zucker/4/alias_for.rb +21 -0
- data/lib/zucker/4/aliases.rb +35 -0
- data/lib/zucker/4/all.rb +8 -0
- data/lib/zucker/4/array.rb +25 -0
- data/lib/zucker/4/array2proc.rb +18 -0
- data/lib/zucker/4/binding.rb +27 -0
- data/lib/zucker/4/blank.rb +28 -0
- data/lib/zucker/4/class2proc.rb +12 -0
- data/lib/zucker/4/debug.rb +8 -0
- data/lib/zucker/4/default.rb +40 -0
- data/lib/zucker/4/egonil.rb +16 -0
- data/lib/zucker/4/engine.rb +69 -0
- data/lib/zucker/4/enumerable.rb +14 -0
- data/lib/zucker/4/hash.rb +21 -0
- data/lib/zucker/4/hash2proc.rb +16 -0
- data/lib/zucker/4/info.rb +173 -0
- data/lib/zucker/4/iterate.rb +25 -0
- data/lib/zucker/4/ivars.rb +28 -0
- data/lib/zucker/4/kernel.rb +27 -0
- data/lib/zucker/4/mcopy.rb +10 -0
- data/lib/zucker/4/mm.rb +33 -0
- data/lib/zucker/4/not.rb +19 -0
- data/lib/zucker/4/os.rb +50 -0
- data/lib/zucker/{q.rb → 4/q.rb} +2 -0
- data/lib/zucker/4/regexp2proc.rb +12 -0
- data/lib/zucker/4/sandbox.rb +23 -0
- data/lib/zucker/4/square_brackets_for.rb +22 -0
- data/lib/zucker/4/string.rb +54 -0
- data/lib/zucker/4/tap.rb +11 -0
- data/lib/zucker/4/unary.rb +24 -0
- data/lib/zucker/4/union.rb +16 -0
- data/lib/zucker/4/version.rb +115 -0
- data/lib/zucker/5/alias_for.rb +21 -0
- data/lib/zucker/5/aliases.rb +51 -0
- data/lib/zucker/5/all.rb +4 -0
- data/lib/zucker/5/array.rb +25 -0
- data/lib/zucker/5/array2proc.rb +18 -0
- data/lib/zucker/5/binding.rb +34 -0
- data/lib/zucker/5/blank.rb +28 -0
- data/lib/zucker/5/cc.rb +25 -0
- data/lib/zucker/5/class2proc.rb +12 -0
- data/lib/zucker/5/control.rb +4 -0
- data/lib/zucker/5/dd.rb +24 -0
- data/lib/zucker/5/debug.rb +4 -0
- data/lib/zucker/5/default.rb +4 -0
- data/lib/zucker/5/egonil.rb +16 -0
- data/lib/zucker/5/engine.rb +69 -0
- data/lib/zucker/5/enumerable.rb +14 -0
- data/lib/zucker/5/env.rb +4 -0
- data/lib/zucker/5/extensions.rb +4 -0
- data/lib/zucker/5/hash.rb +27 -0
- data/lib/zucker/5/hash2proc.rb +16 -0
- data/lib/zucker/5/info.rb +177 -0
- data/lib/zucker/5/iterate.rb +26 -0
- data/lib/zucker/5/ivars.rb +28 -0
- data/lib/zucker/5/kernel.rb +34 -0
- data/lib/zucker/5/mcopy.rb +10 -0
- data/lib/zucker/5/mm.rb +34 -0
- data/lib/zucker/5/not.rb +19 -0
- data/lib/zucker/5/object.rb +4 -0
- data/lib/zucker/5/oo.rb +17 -0
- data/lib/zucker/5/os.rb +49 -0
- data/lib/zucker/5/qq.rb +12 -0
- data/lib/zucker/5/regexp2proc.rb +12 -0
- data/lib/zucker/5/sandbox.rb +25 -0
- data/lib/zucker/5/shortcuts.rb +4 -0
- data/lib/zucker/5/square_brackets_for.rb +21 -0
- data/lib/zucker/5/string.rb +54 -0
- data/lib/zucker/5/tap.rb +11 -0
- data/lib/zucker/5/to_proc.rb +4 -0
- data/lib/zucker/5/unary.rb +24 -0
- data/lib/zucker/5/union.rb +16 -0
- data/lib/zucker/5/version.rb +118 -0
- data/lib/zucker/alias_for.rb +2 -0
- data/lib/zucker/aliases.rb +19 -1
- data/lib/zucker/all.rb +3 -5
- data/lib/zucker/array.rb +2 -0
- data/lib/zucker/array2proc.rb +2 -0
- data/lib/zucker/binding.rb +5 -0
- data/lib/zucker/blank.rb +2 -0
- data/lib/zucker/cc.rb +25 -0
- data/lib/zucker/class2proc.rb +2 -0
- data/lib/zucker/control.rb +4 -0
- data/lib/zucker/dd.rb +23 -0
- data/lib/zucker/debug.rb +2 -4
- data/lib/zucker/default.rb +2 -36
- data/lib/zucker/egonil.rb +2 -0
- data/lib/zucker/engine.rb +3 -1
- data/lib/zucker/enumerable.rb +2 -0
- data/lib/zucker/env.rb +4 -0
- data/lib/zucker/extensions.rb +4 -0
- data/lib/zucker/hash.rb +8 -0
- data/lib/zucker/hash2proc.rb +2 -0
- data/lib/zucker/info.rb +23 -17
- data/lib/zucker/iterate.rb +3 -0
- data/lib/zucker/ivars.rb +2 -0
- data/lib/zucker/kernel.rb +12 -3
- data/lib/zucker/mcopy.rb +2 -0
- data/lib/zucker/mm.rb +5 -2
- data/lib/zucker/not.rb +2 -0
- data/lib/zucker/object.rb +4 -0
- data/lib/zucker/oo.rb +17 -0
- data/lib/zucker/os.rb +5 -2
- data/lib/zucker/qq.rb +12 -0
- data/lib/zucker/regexp2proc.rb +2 -0
- data/lib/zucker/sandbox.rb +4 -0
- data/lib/zucker/shortcuts.rb +4 -0
- data/lib/zucker/square_brackets_for.rb +13 -12
- data/lib/zucker/string.rb +2 -0
- data/lib/zucker/tap.rb +2 -0
- data/lib/zucker/to_proc.rb +4 -0
- data/lib/zucker/unary.rb +2 -0
- data/lib/zucker/union.rb +2 -0
- data/lib/zucker/version.rb +72 -67
- metadata +87 -5
data/lib/zucker/2/iterate.rb
CHANGED
data/lib/zucker/2/ivars.rb
CHANGED
data/lib/zucker/2/kernel.rb
CHANGED
data/lib/zucker/2/mcopy.rb
CHANGED
data/lib/zucker/2/mm.rb
CHANGED
data/lib/zucker/2/regexp2proc.rb
CHANGED
data/lib/zucker/2/sandbox.rb
CHANGED
data/lib/zucker/2/string.rb
CHANGED
data/lib/zucker/2/unary.rb
CHANGED
data/lib/zucker/2/union.rb
CHANGED
data/lib/zucker/3/D.rb
CHANGED
data/lib/zucker/3/alias_for.rb
CHANGED
data/lib/zucker/3/aliases.rb
CHANGED
data/lib/zucker/3/all.rb
CHANGED
data/lib/zucker/3/array.rb
CHANGED
data/lib/zucker/3/array2proc.rb
CHANGED
data/lib/zucker/3/binding.rb
CHANGED
data/lib/zucker/3/blank.rb
CHANGED
data/lib/zucker/3/class2proc.rb
CHANGED
data/lib/zucker/3/debug.rb
CHANGED
data/lib/zucker/3/default.rb
CHANGED
data/lib/zucker/3/egonil.rb
CHANGED
data/lib/zucker/3/enumerable.rb
CHANGED
data/lib/zucker/3/hash.rb
CHANGED
data/lib/zucker/3/hash2proc.rb
CHANGED
data/lib/zucker/3/info.rb
CHANGED
data/lib/zucker/3/iterate.rb
CHANGED
data/lib/zucker/3/ivars.rb
CHANGED
data/lib/zucker/3/kernel.rb
CHANGED
data/lib/zucker/3/mcopy.rb
CHANGED
data/lib/zucker/3/mm.rb
CHANGED
data/lib/zucker/3/not.rb
CHANGED
data/lib/zucker/3/regexp2proc.rb
CHANGED
data/lib/zucker/3/sandbox.rb
CHANGED
data/lib/zucker/3/string.rb
CHANGED
data/lib/zucker/3/tap.rb
CHANGED
data/lib/zucker/3/unary.rb
CHANGED
data/lib/zucker/3/union.rb
CHANGED
data/lib/zucker/{D.rb → 4/D.rb}
RENAMED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
def alias_for(m, *aliases)
|
4
|
+
aliases.each{ |a|
|
5
|
+
class_eval "alias #{a} #{m}"
|
6
|
+
}
|
7
|
+
end
|
8
|
+
alias aliases_for alias_for
|
9
|
+
|
10
|
+
class Module
|
11
|
+
def alias_method_for(m, *alias_methods)
|
12
|
+
alias_methods.each{ |a|
|
13
|
+
class_eval do
|
14
|
+
alias_method a.to_sym, m.to_sym
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
alias alias_methods_for alias_method_for
|
19
|
+
end
|
20
|
+
|
21
|
+
# J-_-L
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
alias is_an? is_a?
|
4
|
+
|
5
|
+
module Enumerable
|
6
|
+
alias with zip
|
7
|
+
alias % zip
|
8
|
+
end
|
9
|
+
|
10
|
+
class Array
|
11
|
+
alias ** product
|
12
|
+
alias contains? include?
|
13
|
+
end
|
14
|
+
|
15
|
+
class String
|
16
|
+
alias contains? include?
|
17
|
+
end
|
18
|
+
|
19
|
+
class Hash
|
20
|
+
alias + merge
|
21
|
+
end
|
22
|
+
|
23
|
+
class Binding
|
24
|
+
#alias [] eval
|
25
|
+
def [](expr)
|
26
|
+
self.eval "#{expr}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# constants - who would use these in real-world code for other things?
|
31
|
+
Infinity = 1.0 / 0.0 # or 2*Float::MAX or Float::INFINITY
|
32
|
+
NaN = 0.0 / 0.0
|
33
|
+
|
34
|
+
# J-_-L
|
35
|
+
|
data/lib/zucker/4/all.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
class Array
|
4
|
+
def ^(other) # TODO: more efficient
|
5
|
+
(self - other) +
|
6
|
+
(other - self)
|
7
|
+
end
|
8
|
+
|
9
|
+
# can take an argument & block to be Rails compatible
|
10
|
+
def sum(identity = 0, &block)
|
11
|
+
# inject(:+)
|
12
|
+
if block_given?
|
13
|
+
map(&block).sum( identity )
|
14
|
+
else
|
15
|
+
inject(:+) || identity
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def chrs
|
20
|
+
self.pack 'C*'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# J-_-L
|
25
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
class Binding
|
4
|
+
def inspect
|
5
|
+
put_vars = lambda { |array|
|
6
|
+
if array.empty?
|
7
|
+
' - none'
|
8
|
+
else
|
9
|
+
array.map{|e| " - #{e}: #{ self.eval '#{e}'}"}*"\n"
|
10
|
+
end
|
11
|
+
}
|
12
|
+
|
13
|
+
"#{self.to_s}
|
14
|
+
local vars
|
15
|
+
#{ put_vars[ self.eval 'local_variables' ] }
|
16
|
+
(instance vars)
|
17
|
+
#{ put_vars[ self.eval 'instance_variables' ] }
|
18
|
+
self
|
19
|
+
- #{self.eval 'self'}
|
20
|
+
block_given?
|
21
|
+
- #{self.eval 'block_given?'}"
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# J-_-L
|
27
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
class Object
|
4
|
+
def blank?
|
5
|
+
if respond_to? :empty? then empty? else !self end
|
6
|
+
end
|
7
|
+
|
8
|
+
def present?
|
9
|
+
!blank?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
{ # what to do # for which classes
|
15
|
+
lambda{ true } => [FalseClass, NilClass],
|
16
|
+
lambda{ false } => [TrueClass, Numeric],
|
17
|
+
lambda{ empty? } => [Array, Hash],
|
18
|
+
lambda{ self !~ /\S/ } => [String],
|
19
|
+
lambda{ self == // } => [Regexp],
|
20
|
+
|
21
|
+
}.each{ |action, klass_array|
|
22
|
+
klass_array.each{ |klass|
|
23
|
+
klass.send :define_method, :blank?, &action
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
# J-_-L
|
28
|
+
|