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
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
require 'zucker'
|
4
|
+
|
5
|
+
# default
|
6
|
+
zucker = %w|
|
7
|
+
alias_for
|
8
|
+
aliases
|
9
|
+
array
|
10
|
+
array2proc
|
11
|
+
blank
|
12
|
+
class2proc
|
13
|
+
egonil
|
14
|
+
engine
|
15
|
+
enumerable
|
16
|
+
hash
|
17
|
+
hash2proc
|
18
|
+
info
|
19
|
+
iterate
|
20
|
+
ivars
|
21
|
+
kernel
|
22
|
+
mcopy
|
23
|
+
not
|
24
|
+
os
|
25
|
+
regexp2proc
|
26
|
+
sandbox
|
27
|
+
square_brackets_for
|
28
|
+
string
|
29
|
+
tap
|
30
|
+
unary
|
31
|
+
union
|
32
|
+
version
|
33
|
+
|
|
34
|
+
|
35
|
+
# remove 1.9 if 1.8
|
36
|
+
if RUBY_VERSION < '1.9'
|
37
|
+
zucker -= %w|not tap union|
|
38
|
+
end
|
39
|
+
|
40
|
+
zucker.each{|rb| require File.join( 'zucker', '4', rb )}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
module RubyEngine
|
4
|
+
class << self
|
5
|
+
# try to guess it
|
6
|
+
@interpreter = case
|
7
|
+
when RUBY_PLATFORM == 'parrot'
|
8
|
+
'cardinal'
|
9
|
+
when Object.constants.include?( :RUBY_ENGINE ) ||
|
10
|
+
Object.constants.include?( 'RUBY_ENGINE' )
|
11
|
+
if RUBY_ENGINE == 'ruby'
|
12
|
+
if RUBY_DESCRIPTION =~ /Enterprise/
|
13
|
+
'ree'
|
14
|
+
else
|
15
|
+
'mri'
|
16
|
+
end
|
17
|
+
else
|
18
|
+
RUBY_ENGINE.to_sym # jruby, rbx, ironruby, macruby, etc.
|
19
|
+
end
|
20
|
+
else # probably 1.8
|
21
|
+
'mri'
|
22
|
+
end
|
23
|
+
|
24
|
+
def is?(what)
|
25
|
+
what === @interpreter
|
26
|
+
end
|
27
|
+
alias is is?
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
@interpreter
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module_function
|
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
|
+
|
69
|
+
# J-_-L
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def self.zip(keys,values)
|
5
|
+
Hash[ *keys.zip( values ).flatten ]
|
6
|
+
end
|
7
|
+
|
8
|
+
def <<(other)
|
9
|
+
case
|
10
|
+
when other.is_a?(Hash)
|
11
|
+
merge! other
|
12
|
+
when other.is_a?(Enumerable) || other.respond_to?(:to_splat)
|
13
|
+
merge! Hash[*other]
|
14
|
+
else
|
15
|
+
raise TypeError, 'can only append other Hashs and Enumerables (or Classes that implement to_splat)'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# J-_-L
|
21
|
+
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
module Info
|
4
|
+
class << Info
|
5
|
+
# hash like access
|
6
|
+
def [](what)
|
7
|
+
send what
|
8
|
+
end
|
9
|
+
|
10
|
+
# list available info methods
|
11
|
+
def list
|
12
|
+
singleton_methods - [:[], :list, '[]', 'list']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module_function
|
17
|
+
|
18
|
+
# current script file
|
19
|
+
def current_file
|
20
|
+
__FILE__
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_file_directory
|
24
|
+
File.dirname(__FILE__)
|
25
|
+
end
|
26
|
+
|
27
|
+
# input
|
28
|
+
def last_input_file
|
29
|
+
$FILENAME
|
30
|
+
end
|
31
|
+
|
32
|
+
def last_input_line_number
|
33
|
+
$.
|
34
|
+
end
|
35
|
+
|
36
|
+
def last_input
|
37
|
+
$_
|
38
|
+
end
|
39
|
+
|
40
|
+
# program
|
41
|
+
def program_name
|
42
|
+
$0
|
43
|
+
end
|
44
|
+
|
45
|
+
def program_arguments
|
46
|
+
$:
|
47
|
+
end
|
48
|
+
|
49
|
+
def loaded_programs
|
50
|
+
$"
|
51
|
+
end
|
52
|
+
|
53
|
+
def program_data
|
54
|
+
::DATA
|
55
|
+
end
|
56
|
+
|
57
|
+
def child_program_status
|
58
|
+
$CHILD_STATUS
|
59
|
+
end
|
60
|
+
|
61
|
+
# system info
|
62
|
+
def environment
|
63
|
+
::ENV
|
64
|
+
end
|
65
|
+
alias env environment
|
66
|
+
|
67
|
+
def working_directory
|
68
|
+
Dir.pwd
|
69
|
+
end
|
70
|
+
|
71
|
+
def platform
|
72
|
+
::RUBY_PLATFORM
|
73
|
+
end
|
74
|
+
|
75
|
+
def os
|
76
|
+
RbConfig::CONFIG['host_os']
|
77
|
+
end
|
78
|
+
|
79
|
+
def process_id
|
80
|
+
$$
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_path
|
84
|
+
$:
|
85
|
+
end
|
86
|
+
|
87
|
+
# current
|
88
|
+
def current_line
|
89
|
+
__LINE__
|
90
|
+
end
|
91
|
+
|
92
|
+
def current_method # 1.9
|
93
|
+
__method__
|
94
|
+
end
|
95
|
+
|
96
|
+
def current_callstack
|
97
|
+
caller
|
98
|
+
end
|
99
|
+
|
100
|
+
# dealing with strings
|
101
|
+
def gets_separator
|
102
|
+
$/
|
103
|
+
end
|
104
|
+
|
105
|
+
def join_separator
|
106
|
+
$,
|
107
|
+
end
|
108
|
+
|
109
|
+
def print_separator
|
110
|
+
$,
|
111
|
+
end
|
112
|
+
|
113
|
+
def split_separator
|
114
|
+
$;
|
115
|
+
end
|
116
|
+
|
117
|
+
# misc
|
118
|
+
def security_level
|
119
|
+
$SAFE
|
120
|
+
end
|
121
|
+
|
122
|
+
def warnings_activated?
|
123
|
+
$VERBOSE
|
124
|
+
end
|
125
|
+
|
126
|
+
def debug_activated?
|
127
|
+
$DEBUG
|
128
|
+
end
|
129
|
+
|
130
|
+
def last_exception
|
131
|
+
$!
|
132
|
+
end
|
133
|
+
|
134
|
+
# defined objects
|
135
|
+
def global_variables
|
136
|
+
Object.send :global_variables
|
137
|
+
end
|
138
|
+
|
139
|
+
def global_constants
|
140
|
+
Object.constants
|
141
|
+
end
|
142
|
+
|
143
|
+
# encoding (1.9)
|
144
|
+
def source_encoding
|
145
|
+
__ENCODING__
|
146
|
+
end
|
147
|
+
|
148
|
+
def external_encoding
|
149
|
+
Encoding.default_external
|
150
|
+
end
|
151
|
+
|
152
|
+
def internal_encoding
|
153
|
+
Encoding.default_internal
|
154
|
+
end
|
155
|
+
|
156
|
+
# ruby version info
|
157
|
+
def ruby_version
|
158
|
+
::RUBY_VERSION
|
159
|
+
end
|
160
|
+
|
161
|
+
def ruby_patchlevel
|
162
|
+
::RUBY_PATCHLEVEL
|
163
|
+
end
|
164
|
+
|
165
|
+
def ruby_description
|
166
|
+
::RUBY_DESCRIPTION
|
167
|
+
end
|
168
|
+
|
169
|
+
def ruby_release_date
|
170
|
+
::RUBY_RELEASE_DATE
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
def iterate(*params)
|
4
|
+
# params.shift.zip(*params).each{ |*elements| yield *elements }
|
5
|
+
|
6
|
+
first = params.shift
|
7
|
+
if params.empty? # single param - like each
|
8
|
+
if block_given?
|
9
|
+
first.map{|e| yield e }
|
10
|
+
else
|
11
|
+
first.map
|
12
|
+
end
|
13
|
+
else
|
14
|
+
padded_first = Array.new( [first, *params].max_by(&:size).size ){|i| first[i] } # append nils
|
15
|
+
obj = padded_first.zip *params
|
16
|
+
if block_given?
|
17
|
+
obj.map{|es| yield *es }
|
18
|
+
else
|
19
|
+
obj.map.to_enum
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# J-_-L
|
25
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
def instance_variables_from(obj, *only)
|
4
|
+
iter =
|
5
|
+
if obj.is_a? Binding
|
6
|
+
obj.eval('local_variables').map{|e| [obj.eval("#{e}"), e] }
|
7
|
+
elsif obj.is_a? Hash
|
8
|
+
obj.map{|k,v| [v,k] }
|
9
|
+
else
|
10
|
+
# elsif obj.is_a? Enumerable
|
11
|
+
obj.each.with_index
|
12
|
+
end
|
13
|
+
|
14
|
+
ret = []
|
15
|
+
iter.each{ |value, arg|
|
16
|
+
arg = arg.to_s
|
17
|
+
if only.include?(arg) || only.include?(arg.to_sym) || only.empty?
|
18
|
+
arg = '_' + arg if (48..57).member? arg.unpack('C')[0] # 1.8+1.9
|
19
|
+
ret << ivar = :"@#{arg}"
|
20
|
+
self.instance_variable_set ivar, value
|
21
|
+
end
|
22
|
+
}
|
23
|
+
ret
|
24
|
+
end
|
25
|
+
alias ivars instance_variables_from
|
26
|
+
|
27
|
+
# J-_-L
|
28
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
def activate_warnings!
|
5
|
+
$VERBOSE = true
|
6
|
+
end
|
7
|
+
|
8
|
+
def deactivate_warnings!
|
9
|
+
$VERBOSE = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def library?
|
13
|
+
__FILE__ != $PROGRAM_NAME
|
14
|
+
end
|
15
|
+
|
16
|
+
def executed_directly?
|
17
|
+
__FILE__ == $PROGRAM_NAME
|
18
|
+
end
|
19
|
+
alias standalone? executed_directly?
|
20
|
+
|
21
|
+
def ignore_sigint! # ctrl+c
|
22
|
+
Signal.trap *%w|SIGINT IGNORE|
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# J-_-L
|
27
|
+
|