zucker 3 → 4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/Rakefile +3 -3
- data/lib/zucker.rb +4 -2
- data/lib/zucker/aliases.rb +6 -1
- data/lib/zucker/binding.rb +5 -1
- data/lib/zucker/debug.rb +1 -1
- data/lib/zucker/default.rb +3 -0
- data/lib/zucker/engine.rb +67 -0
- data/lib/zucker/info.rb +4 -0
- data/lib/zucker/kernel.rb +4 -27
- data/lib/zucker/os.rb +46 -0
- data/lib/zucker/q.rb +5 -0
- data/lib/zucker/sandbox.rb +14 -12
- data/lib/zucker/string.rb +8 -3
- data/lib/zucker/version.rb +113 -0
- metadata +9 -5
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
2010-09-01 | Zucker 4
|
2
|
+
|
3
|
+
* added RubyEngine constant
|
4
|
+
* added RubyVersion constant
|
5
|
+
* added OS constant
|
6
|
+
* added q debug method (like p but on one line)
|
7
|
+
* added String#-
|
8
|
+
|
1
9
|
2010-08-14 | Zucker 3
|
2
10
|
* added tap cube
|
3
11
|
* added Object#not
|
@@ -24,3 +32,4 @@
|
|
24
32
|
|
25
33
|
2010-08-05 | Zucker 0
|
26
34
|
* pre-release for rug-b talk
|
35
|
+
|
data/Rakefile
CHANGED
@@ -26,10 +26,10 @@ spec = Gem::Specification.new do |s|
|
|
26
26
|
s.name = 'zucker'
|
27
27
|
s.version = Zucker::VERSION
|
28
28
|
s.date = Zucker::DATE
|
29
|
-
s.authors = ['
|
29
|
+
s.authors = ['Jan Lelis','and many others']
|
30
30
|
s.email = 'mail@janlelis.de'
|
31
|
-
s.summary = "
|
32
|
-
Adds
|
31
|
+
s.summary = "Sweeten your Ruby code with this syntactic sugar :).
|
32
|
+
Adds a lot of little helpers that you do not want to miss again.
|
33
33
|
See http://rubyzucker.info"
|
34
34
|
s.homepage = 'http://rubyzucker.info'
|
35
35
|
s.files = PKG_FILES.to_a
|
data/lib/zucker.rb
CHANGED
data/lib/zucker/aliases.rb
CHANGED
@@ -7,6 +7,11 @@ end
|
|
7
7
|
|
8
8
|
class Array
|
9
9
|
alias ** product
|
10
|
+
alias contains? include?
|
11
|
+
end
|
12
|
+
|
13
|
+
class String
|
14
|
+
alias contains? include?
|
10
15
|
end
|
11
16
|
|
12
17
|
class Hash
|
@@ -21,7 +26,7 @@ class Binding
|
|
21
26
|
end
|
22
27
|
|
23
28
|
# constants - who would use these in real-world code for other things?
|
24
|
-
Infinity = 1.0 / 0.0 # or 2*Float::MAX
|
29
|
+
Infinity = 1.0 / 0.0 # or 2*Float::MAX or Float::INFINITY
|
25
30
|
NaN = 0.0 / 0.0
|
26
31
|
|
27
32
|
# J-_-L
|
data/lib/zucker/binding.rb
CHANGED
data/lib/zucker/debug.rb
CHANGED
data/lib/zucker/default.rb
CHANGED
@@ -9,6 +9,7 @@ array2proc
|
|
9
9
|
blank
|
10
10
|
class2proc
|
11
11
|
egonil
|
12
|
+
engine
|
12
13
|
enumerable
|
13
14
|
hash
|
14
15
|
hash2proc
|
@@ -18,6 +19,7 @@ ivars
|
|
18
19
|
kernel
|
19
20
|
mcopy
|
20
21
|
not
|
22
|
+
os
|
21
23
|
regexp2proc
|
22
24
|
sandbox
|
23
25
|
square_brackets_for
|
@@ -25,6 +27,7 @@ string
|
|
25
27
|
tap
|
26
28
|
unary
|
27
29
|
union
|
30
|
+
version
|
28
31
|
|
|
29
32
|
|
30
33
|
# remove 1.9 if 1.8
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module RubyEngine
|
2
|
+
# try to guess the interpreter
|
3
|
+
@interpreter = case
|
4
|
+
when RUBY_PLATFORM == 'parrot'
|
5
|
+
'cardinal'
|
6
|
+
when Object.constants.include?( :RUBY_ENGINE ) ||
|
7
|
+
Object.constants.include?( 'RUBY_ENGINE' )
|
8
|
+
if RUBY_ENGINE == 'ruby'
|
9
|
+
if RUBY_DESCRIPTION =~ /Enterprise/
|
10
|
+
'ree'
|
11
|
+
else
|
12
|
+
'mri'
|
13
|
+
end
|
14
|
+
else
|
15
|
+
RUBY_ENGINE.to_sym # jruby, rbx, ironruby, macruby, etc.
|
16
|
+
end
|
17
|
+
else # probably 1.8
|
18
|
+
'mri'
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def is?(what)
|
23
|
+
what === @interpreter
|
24
|
+
end
|
25
|
+
alias is is?
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
@interpreter.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
# ask methods
|
32
|
+
|
33
|
+
def mri?
|
34
|
+
RubyEngine.is? 'mri'
|
35
|
+
end
|
36
|
+
alias official_ruby? mri?
|
37
|
+
alias ruby? mri?
|
38
|
+
|
39
|
+
def jruby?
|
40
|
+
RubyEngine.is? 'jruby'
|
41
|
+
end
|
42
|
+
alias java? jruby?
|
43
|
+
|
44
|
+
def rubinius?
|
45
|
+
RubyEngine.is? 'rbx'
|
46
|
+
end
|
47
|
+
alias rbx? rubinius?
|
48
|
+
|
49
|
+
def ree?
|
50
|
+
RubyEngine.is? 'ree'
|
51
|
+
end
|
52
|
+
alias enterprise? ree?
|
53
|
+
|
54
|
+
def ironruby?
|
55
|
+
RubyEngine.is? 'ironruby'
|
56
|
+
end
|
57
|
+
alias iron_ruby? ironruby?
|
58
|
+
|
59
|
+
def cardinal?
|
60
|
+
RubyEngine.is? 'cardinal'
|
61
|
+
end
|
62
|
+
alias parrot? cardinal?
|
63
|
+
alias perl? cardinal?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# J-_-L
|
data/lib/zucker/info.rb
CHANGED
data/lib/zucker/kernel.rb
CHANGED
@@ -2,46 +2,23 @@ module Kernel
|
|
2
2
|
def activate_warnings!
|
3
3
|
$VERBOSE = true
|
4
4
|
end
|
5
|
-
|
5
|
+
|
6
6
|
def deactivate_warnings!
|
7
7
|
$VERBOSE = false
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def library?
|
11
11
|
__FILE__ != $PROGRAM_NAME
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def executed_directly?
|
15
15
|
__FILE__ == $PROGRAM_NAME
|
16
16
|
end
|
17
17
|
alias standalone? executed_directly?
|
18
|
-
|
18
|
+
|
19
19
|
def ignore_sigint! # ctrl+c
|
20
20
|
Signal.trap *%w|SIGINT IGNORE|
|
21
21
|
end
|
22
|
-
|
23
|
-
# version getter
|
24
|
-
def ruby_1_9?
|
25
|
-
RUBY_VERSION[2,1] == '9'
|
26
|
-
end
|
27
|
-
|
28
|
-
def ruby_1_8?
|
29
|
-
RUBY_VERSION[2,1] == '8'
|
30
|
-
end
|
31
|
-
|
32
|
-
def ruby_1_9!
|
33
|
-
if RUBY_VERSION[2,1] != '9'
|
34
|
-
fail NotImplementedError, "Sorry, this script requires Ruby 1.9, but was executed with a different Ruby version!"
|
35
|
-
end
|
36
|
-
true
|
37
|
-
end
|
38
|
-
|
39
|
-
def ruby_1_8!
|
40
|
-
if RUBY_VERSION[2,1] != '8'
|
41
|
-
fail NotImplementedError, "Sorry, this script requires Ruby 1.8, but was executed with a different Ruby version!"
|
42
|
-
end
|
43
|
-
true
|
44
|
-
end
|
45
22
|
end
|
46
23
|
|
47
24
|
# J-_-L
|
data/lib/zucker/os.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
module OS
|
4
|
+
class << OS
|
5
|
+
def is?(what)
|
6
|
+
what === RbConfig::CONFIG['host_os']
|
7
|
+
end
|
8
|
+
alias is is?
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
RbConfig::CONFIG['host_os']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def linux?
|
18
|
+
OS.is? /linux|cygwin/
|
19
|
+
end
|
20
|
+
|
21
|
+
def mac?
|
22
|
+
OS.is? /mac|darwin/
|
23
|
+
end
|
24
|
+
|
25
|
+
def bsd?
|
26
|
+
OS.is? /bsd/
|
27
|
+
end
|
28
|
+
|
29
|
+
def windows?
|
30
|
+
OS.is? /mswin|win|mingw/
|
31
|
+
end
|
32
|
+
|
33
|
+
def solaris?
|
34
|
+
OS.is? /solaris|sunos/
|
35
|
+
end
|
36
|
+
|
37
|
+
def posix?
|
38
|
+
linux? or mac? or bsd? or solaris? or Process.respond_to?(:fork)
|
39
|
+
end
|
40
|
+
|
41
|
+
#def symbian?
|
42
|
+
#TODO who knows what symbian returns?
|
43
|
+
#end
|
44
|
+
end
|
45
|
+
|
46
|
+
# J-_-L
|
data/lib/zucker/q.rb
ADDED
data/lib/zucker/sandbox.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if rescueblock_or_default.
|
9
|
-
rescueblock_or_default.
|
1
|
+
module Kernel
|
2
|
+
def sandbox(rescueblock_or_default=nil)
|
3
|
+
Thread.start do
|
4
|
+
$SAFE = 4
|
5
|
+
yield
|
6
|
+
end.value
|
7
|
+
rescue SecurityError => e
|
8
|
+
if !rescueblock_or_default.nil?
|
9
|
+
if rescueblock_or_default.is_a? Proc
|
10
|
+
rescueblock_or_default.call e
|
11
|
+
else
|
12
|
+
rescueblock_or_default
|
13
|
+
end
|
10
14
|
else
|
11
|
-
|
15
|
+
raise e
|
12
16
|
end
|
13
|
-
else
|
14
|
-
raise e
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
data/lib/zucker/string.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
class String
|
2
|
+
def -(rem)
|
3
|
+
gsub( Regexp === rem ? rem : rem.to_s, '' )
|
4
|
+
end
|
5
|
+
|
2
6
|
def ^(pos)
|
3
7
|
pos = pos.to_i
|
4
8
|
if pos >= 0
|
@@ -9,15 +13,16 @@ class String
|
|
9
13
|
end
|
10
14
|
|
11
15
|
def lchomp(arg = $/)
|
12
|
-
|
16
|
+
reverse.chomp(arg).reverse
|
13
17
|
end
|
14
18
|
|
15
19
|
def lchomp!(arg = $/)
|
16
|
-
|
20
|
+
reverse.chomp!(arg).reverse
|
17
21
|
end
|
18
22
|
|
19
23
|
def ords
|
20
|
-
|
24
|
+
unpack 'C*'
|
25
|
+
# bytes.to_a
|
21
26
|
end
|
22
27
|
|
23
28
|
def constantize(default_value = nil) # always uses global scope as in AS... is this good?
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module RubyVersion
|
2
|
+
class << self
|
3
|
+
def to_s
|
4
|
+
RUBY_VERSION
|
5
|
+
end
|
6
|
+
|
7
|
+
def is?(other_version = nil)
|
8
|
+
compare other_version
|
9
|
+
end
|
10
|
+
alias is is?
|
11
|
+
|
12
|
+
# accessors
|
13
|
+
|
14
|
+
def major
|
15
|
+
RUBY_VERSION.to_i
|
16
|
+
end
|
17
|
+
alias main major
|
18
|
+
|
19
|
+
def minor
|
20
|
+
RUBY_VERSION.split('.')[1].to_i
|
21
|
+
end
|
22
|
+
alias mini minor
|
23
|
+
|
24
|
+
def tiny
|
25
|
+
RUBY_VERSION.split('.')[2].to_i
|
26
|
+
end
|
27
|
+
alias teeny tiny
|
28
|
+
|
29
|
+
def patchlevel
|
30
|
+
RUBY_PATCHLEVEL
|
31
|
+
end
|
32
|
+
|
33
|
+
def platform
|
34
|
+
RUBY_PLATFORM
|
35
|
+
end
|
36
|
+
|
37
|
+
def release_date
|
38
|
+
Date.parse RUBY_RELEASE_DATE
|
39
|
+
end
|
40
|
+
alias date release_date
|
41
|
+
|
42
|
+
def description
|
43
|
+
RUBY_DESCRIPTION
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def compare(other_version)
|
49
|
+
case other_version
|
50
|
+
when nil
|
51
|
+
matcher
|
52
|
+
when Float
|
53
|
+
other_version == RUBY_VERSION.to_f
|
54
|
+
else
|
55
|
+
other_version.to_s == RUBY_VERSION
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def matcher
|
61
|
+
return @ruby if @ruby
|
62
|
+
|
63
|
+
@ruby = RUBY_VERSION.dup
|
64
|
+
@ruby.instance_eval do
|
65
|
+
alias below <
|
66
|
+
alias below? <
|
67
|
+
alias at_most <=
|
68
|
+
alias at_most? <=
|
69
|
+
alias above >
|
70
|
+
alias above? >
|
71
|
+
alias at_least >=
|
72
|
+
alias at_least? >=
|
73
|
+
alias exactly ==
|
74
|
+
alias exactly? ==
|
75
|
+
def not(other)
|
76
|
+
self != other
|
77
|
+
end
|
78
|
+
alias not? not
|
79
|
+
alias between between?
|
80
|
+
|
81
|
+
def newer_than(other)
|
82
|
+
case other.class
|
83
|
+
when Date, Time
|
84
|
+
other.class.parse(RUBY_RELEASE_DATE) > other
|
85
|
+
else
|
86
|
+
RUBY_RELEASE_DATE > other.to_s
|
87
|
+
end
|
88
|
+
end
|
89
|
+
alias newer_than? newer_than
|
90
|
+
|
91
|
+
def older_than(other)
|
92
|
+
case other.class
|
93
|
+
when Date, Time
|
94
|
+
other.class.parse(RUBY_RELEASE_DATE) < other
|
95
|
+
else
|
96
|
+
RUBY_RELEASE_DATE < other.to_s
|
97
|
+
end
|
98
|
+
end
|
99
|
+
alias older_than? older_than
|
100
|
+
|
101
|
+
def released_today
|
102
|
+
RubyVersion.date == Date.today
|
103
|
+
end
|
104
|
+
alias released_today? released_today
|
105
|
+
end
|
106
|
+
|
107
|
+
@ruby.freeze
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# J-_-L
|
metadata
CHANGED
@@ -3,17 +3,17 @@ name: zucker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
-
|
7
|
-
version: "
|
6
|
+
- 4
|
7
|
+
version: "4"
|
8
8
|
platform: ruby
|
9
9
|
authors:
|
10
|
-
- Based on the thoughts of many people ;)
|
11
10
|
- Jan Lelis
|
11
|
+
- and many others
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2010-
|
16
|
+
date: 2010-09-01 00:00:00 +02:00
|
17
17
|
default_executable:
|
18
18
|
dependencies: []
|
19
19
|
|
@@ -89,9 +89,12 @@ files:
|
|
89
89
|
- lib/zucker/1/mcopy.rb
|
90
90
|
- lib/zucker/1/debug.rb
|
91
91
|
- lib/zucker/1/sandbox.rb
|
92
|
+
- lib/zucker/os.rb
|
92
93
|
- lib/zucker/array.rb
|
94
|
+
- lib/zucker/engine.rb
|
93
95
|
- lib/zucker/all.rb
|
94
96
|
- lib/zucker/array2proc.rb
|
97
|
+
- lib/zucker/q.rb
|
95
98
|
- lib/zucker/default.rb
|
96
99
|
- lib/zucker/D.rb
|
97
100
|
- lib/zucker/string.rb
|
@@ -132,6 +135,7 @@ files:
|
|
132
135
|
- lib/zucker/2/sandbox.rb
|
133
136
|
- lib/zucker/regexp2proc.rb
|
134
137
|
- lib/zucker/square_brackets_for.rb
|
138
|
+
- lib/zucker/version.rb
|
135
139
|
- lib/zucker/aliases.rb
|
136
140
|
- lib/zucker/mm.rb
|
137
141
|
- lib/zucker/enumerable.rb
|
@@ -173,6 +177,6 @@ rubyforge_project:
|
|
173
177
|
rubygems_version: 1.3.7
|
174
178
|
signing_key:
|
175
179
|
specification_version: 3
|
176
|
-
summary:
|
180
|
+
summary: Sweeten your Ruby code with this syntactic sugar :). Adds a lot of little helpers that you do not want to miss again. See http://rubyzucker.info
|
177
181
|
test_files: []
|
178
182
|
|