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/alias_for.rb
CHANGED
data/lib/zucker/aliases.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
class Object
|
4
|
+
alias is_an? is_a? # thanks to utility_belt
|
5
|
+
end
|
2
6
|
|
3
7
|
module Enumerable
|
4
8
|
alias with zip
|
@@ -25,6 +29,20 @@ class Binding
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
32
|
+
class << File
|
33
|
+
alias filename basename # thanks rdp :)
|
34
|
+
end
|
35
|
+
|
36
|
+
class << Dir
|
37
|
+
def join(*args)
|
38
|
+
File.join(*args)
|
39
|
+
end
|
40
|
+
|
41
|
+
def split(*args)
|
42
|
+
File.split(*args)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
28
46
|
# constants - who would use these in real-world code for other things?
|
29
47
|
Infinity = 1.0 / 0.0 # or 2*Float::MAX or Float::INFINITY
|
30
48
|
NaN = 0.0 / 0.0
|
data/lib/zucker/all.rb
CHANGED
data/lib/zucker/array.rb
CHANGED
data/lib/zucker/array2proc.rb
CHANGED
data/lib/zucker/binding.rb
CHANGED
data/lib/zucker/blank.rb
CHANGED
data/lib/zucker/cc.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
private
|
5
|
+
|
6
|
+
def c(show_irb = false)
|
7
|
+
method_stack = caller.reverse.map{ |m|
|
8
|
+
m.rindex( /:\d+(:in `(.*)')?$/ )
|
9
|
+
$2
|
10
|
+
}.compact
|
11
|
+
|
12
|
+
if !show_irb && a = method_stack.index( 'irb_binding' )
|
13
|
+
method_stack = [ method_stack[0], '(irb)', *method_stack[a+1..-1] ]
|
14
|
+
end
|
15
|
+
|
16
|
+
# puts method_stack.map.with_index{ |m, i|
|
17
|
+
method_stack.each_with_index{ |m, i|
|
18
|
+
puts " "*i + m
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
alias cc c
|
23
|
+
end
|
24
|
+
|
25
|
+
# J-_-L
|
data/lib/zucker/class2proc.rb
CHANGED
data/lib/zucker/dd.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
def d(*args, &block)
|
5
|
+
if args.empty?
|
6
|
+
tap{
|
7
|
+
if block_given?
|
8
|
+
puts yield self
|
9
|
+
else
|
10
|
+
puts self.inspect
|
11
|
+
end
|
12
|
+
}
|
13
|
+
else
|
14
|
+
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!"
|
15
|
+
# eval ...
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
alias dd d
|
20
|
+
end
|
21
|
+
|
22
|
+
# J-_-L
|
23
|
+
|
data/lib/zucker/debug.rb
CHANGED
data/lib/zucker/default.rb
CHANGED
@@ -1,38 +1,4 @@
|
|
1
1
|
require 'zucker'
|
2
|
+
Zucker.require_all
|
2
3
|
|
3
|
-
#
|
4
|
-
zucker = %w|
|
5
|
-
alias_for
|
6
|
-
aliases
|
7
|
-
array
|
8
|
-
array2proc
|
9
|
-
blank
|
10
|
-
class2proc
|
11
|
-
egonil
|
12
|
-
engine
|
13
|
-
enumerable
|
14
|
-
hash
|
15
|
-
hash2proc
|
16
|
-
info
|
17
|
-
iterate
|
18
|
-
ivars
|
19
|
-
kernel
|
20
|
-
mcopy
|
21
|
-
not
|
22
|
-
os
|
23
|
-
regexp2proc
|
24
|
-
sandbox
|
25
|
-
square_brackets_for
|
26
|
-
string
|
27
|
-
tap
|
28
|
-
unary
|
29
|
-
union
|
30
|
-
version
|
31
|
-
|
|
32
|
-
|
33
|
-
# remove 1.9 if 1.8
|
34
|
-
if RUBY_VERSION < '1.9'
|
35
|
-
zucker -= %w|not tap union|
|
36
|
-
end
|
37
|
-
|
38
|
-
zucker.each{|rb| require File.join( 'zucker', rb )}
|
4
|
+
# J-_-L
|
data/lib/zucker/egonil.rb
CHANGED
data/lib/zucker/engine.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
1
3
|
module RubyEngine
|
2
4
|
# try to guess the interpreter
|
3
5
|
@interpreter = case
|
@@ -12,7 +14,7 @@ module RubyEngine
|
|
12
14
|
'mri'
|
13
15
|
end
|
14
16
|
else
|
15
|
-
RUBY_ENGINE.
|
17
|
+
RUBY_ENGINE.to_s # jruby, rbx, ironruby, macruby, etc.
|
16
18
|
end
|
17
19
|
else # probably 1.8
|
18
20
|
'mri'
|
data/lib/zucker/enumerable.rb
CHANGED
data/lib/zucker/env.rb
ADDED
data/lib/zucker/hash.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
1
3
|
class Hash
|
2
4
|
def self.zip(keys,values)
|
3
5
|
Hash[ *keys.zip( values ).flatten ]
|
@@ -13,6 +15,12 @@ class Hash
|
|
13
15
|
raise TypeError, 'can only append other Hashs and Enumerables (or Classes that implement to_splat)'
|
14
16
|
end
|
15
17
|
end
|
18
|
+
|
19
|
+
def &(other)
|
20
|
+
Hash[ *select{ |k,v|
|
21
|
+
other[k] == v
|
22
|
+
}.flatten ]
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
26
|
# J-_-L
|
data/lib/zucker/hash2proc.rb
CHANGED
data/lib/zucker/info.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
1
3
|
module Info
|
2
|
-
class <<
|
4
|
+
class << self
|
3
5
|
# hash like access
|
4
6
|
def [](what)
|
5
7
|
send what
|
@@ -13,15 +15,6 @@ module Info
|
|
13
15
|
|
14
16
|
module_function
|
15
17
|
|
16
|
-
# current script file
|
17
|
-
def current_file
|
18
|
-
__FILE__
|
19
|
-
end
|
20
|
-
|
21
|
-
def current_file_directory
|
22
|
-
File.dirname(__FILE__)
|
23
|
-
end
|
24
|
-
|
25
18
|
# input
|
26
19
|
def last_input_file
|
27
20
|
$FILENAME
|
@@ -83,12 +76,25 @@ module Info
|
|
83
76
|
end
|
84
77
|
|
85
78
|
# current
|
86
|
-
|
87
|
-
|
79
|
+
|
80
|
+
def current_file # __FILE__
|
81
|
+
return $` if caller[0].rindex(/:\d+(:in `.*')?$/)
|
88
82
|
end
|
89
83
|
|
90
|
-
def
|
91
|
-
|
84
|
+
def current_file_directory
|
85
|
+
if current_file[0,1] == '(' && current_file[-1,1] == ')'
|
86
|
+
current_file
|
87
|
+
else
|
88
|
+
File.dirname(current_file)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def current_line # __LINE__
|
93
|
+
return $1.to_i if caller[0].rindex( /:(\d+)(:in `.*')?$/ )
|
94
|
+
end
|
95
|
+
|
96
|
+
def current_method # __method__ (except aliases)
|
97
|
+
return $1.to_sym if caller(1)[0].rindex( /\`([^\']+)\'/ )
|
92
98
|
end
|
93
99
|
|
94
100
|
def current_callstack
|
@@ -139,9 +145,9 @@ module Info
|
|
139
145
|
end
|
140
146
|
|
141
147
|
# encoding (1.9)
|
142
|
-
def source_encoding
|
143
|
-
|
144
|
-
end
|
148
|
+
#def source_encoding
|
149
|
+
# __ENCODING__
|
150
|
+
#end
|
145
151
|
|
146
152
|
def external_encoding
|
147
153
|
Encoding.default_external
|
data/lib/zucker/iterate.rb
CHANGED
data/lib/zucker/ivars.rb
CHANGED
data/lib/zucker/kernel.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
1
3
|
module Kernel
|
4
|
+
private
|
5
|
+
|
2
6
|
def activate_warnings!
|
3
7
|
$VERBOSE = true
|
4
8
|
end
|
@@ -8,18 +12,23 @@ module Kernel
|
|
8
12
|
end
|
9
13
|
|
10
14
|
def library?
|
11
|
-
|
15
|
+
caller[0].rindex(/:\d+(:in `.*')?$/)
|
16
|
+
$PROGRAM_NAME != $` # __FILE__
|
12
17
|
end
|
13
18
|
|
14
19
|
def executed_directly?
|
15
|
-
|
20
|
+
caller[0].rindex(/:\d+(:in `.*')?$/)
|
21
|
+
$PROGRAM_NAME == $` # __FILE__
|
16
22
|
end
|
17
23
|
alias standalone? executed_directly?
|
18
24
|
|
25
|
+
def irb?
|
26
|
+
!!(( IRB and $0 == 'irb' ) rescue nil)
|
27
|
+
end
|
28
|
+
|
19
29
|
def ignore_sigint! # ctrl+c
|
20
30
|
Signal.trap *%w|SIGINT IGNORE|
|
21
31
|
end
|
22
32
|
end
|
23
33
|
|
24
34
|
# J-_-L
|
25
|
-
|
data/lib/zucker/mcopy.rb
CHANGED
data/lib/zucker/mm.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
1
3
|
module Kernel
|
2
|
-
def
|
4
|
+
def m(levels = 1)
|
3
5
|
if self.is_a? Module
|
4
6
|
klass, method_function = self, :public_methods
|
5
7
|
else
|
@@ -24,7 +26,8 @@ module Kernel
|
|
24
26
|
self # or whatever
|
25
27
|
end
|
26
28
|
|
27
|
-
alias mm
|
29
|
+
alias mm m
|
30
|
+
alias method_list m
|
28
31
|
end
|
29
32
|
|
30
33
|
# J-_-L
|
data/lib/zucker/not.rb
CHANGED
data/lib/zucker/oo.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
private
|
5
|
+
|
6
|
+
def o(desc = nil)
|
7
|
+
caller[0].rindex( /:(\d+)(:in (`.*'))?$/ )
|
8
|
+
m = $3 ? "method #$3, " : ""
|
9
|
+
d = desc ? "#{desc}: r" : 'R'
|
10
|
+
|
11
|
+
puts ret = "#{d}eached #{m}line #$1 of file #$`"
|
12
|
+
# [$`, $1.to_i, $3.to_sym, desc]
|
13
|
+
end
|
14
|
+
alias oo o
|
15
|
+
end
|
16
|
+
|
17
|
+
# J-_-L
|