zucker 2 → 3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -0
- data/README +4 -1
- data/Rakefile +17 -7
- data/lib/zucker.rb +7 -1
- data/lib/zucker/2/all.rb +2 -2
- data/lib/zucker/2/debug.rb +3 -3
- data/lib/zucker/2/default.rb +1 -1
- data/lib/zucker/3/D.rb +19 -0
- data/lib/zucker/3/alias_for.rb +19 -0
- data/lib/zucker/3/aliases.rb +28 -0
- data/lib/zucker/3/all.rb +6 -0
- data/lib/zucker/3/array.rb +23 -0
- data/lib/zucker/3/array2proc.rb +16 -0
- data/lib/zucker/3/binding.rb +25 -0
- data/lib/zucker/3/blank.rb +26 -0
- data/lib/zucker/3/class2proc.rb +10 -0
- data/lib/zucker/3/debug.rb +6 -0
- data/lib/zucker/3/default.rb +35 -0
- data/lib/zucker/3/egonil.rb +14 -0
- data/lib/zucker/3/enumerable.rb +12 -0
- data/lib/zucker/3/hash.rb +19 -0
- data/lib/zucker/3/hash2proc.rb +14 -0
- data/lib/zucker/3/info.rb +167 -0
- data/lib/zucker/3/iterate.rb +23 -0
- data/lib/zucker/3/ivars.rb +26 -0
- data/lib/zucker/3/kernel.rb +48 -0
- data/lib/zucker/3/mcopy.rb +8 -0
- data/lib/zucker/3/mm.rb +31 -0
- data/lib/zucker/3/not.rb +17 -0
- data/lib/zucker/3/regexp2proc.rb +10 -0
- data/lib/zucker/3/sandbox.rb +19 -0
- data/lib/zucker/3/square_brackets_for.rb +20 -0
- data/lib/zucker/3/string.rb +47 -0
- data/lib/zucker/3/tap.rb +9 -0
- data/lib/zucker/3/unary.rb +22 -0
- data/lib/zucker/3/union.rb +14 -0
- data/lib/zucker/alias_for.rb +19 -0
- data/lib/zucker/array.rb +8 -2
- data/lib/zucker/debug.rb +2 -0
- data/lib/zucker/default.rb +11 -1
- data/lib/zucker/info.rb +5 -2
- data/lib/zucker/kernel.rb +41 -11
- data/lib/zucker/mcopy.rb +0 -1
- data/lib/zucker/not.rb +17 -0
- data/lib/zucker/string.rb +24 -2
- data/lib/zucker/tap.rb +9 -0
- metadata +41 -160
- data/lib/zucker/1/desc/D.yaml +0 -23
- data/lib/zucker/1/desc/aliases.yaml +0 -16
- data/lib/zucker/1/desc/array.yaml +0 -14
- data/lib/zucker/1/desc/array2proc.yaml +0 -13
- data/lib/zucker/1/desc/binding.yaml +0 -10
- data/lib/zucker/1/desc/blank.yaml +0 -12
- data/lib/zucker/1/desc/class2proc.yaml +0 -12
- data/lib/zucker/1/desc/egonil.yaml +0 -17
- data/lib/zucker/1/desc/enumerable.yaml +0 -11
- data/lib/zucker/1/desc/hash.yaml +0 -12
- data/lib/zucker/1/desc/hash2proc.yaml +0 -11
- data/lib/zucker/1/desc/iterate.yaml +0 -17
- data/lib/zucker/1/desc/ivars.yaml +0 -20
- data/lib/zucker/1/desc/kernel.yaml +0 -13
- data/lib/zucker/1/desc/mcopy.yaml +0 -12
- data/lib/zucker/1/desc/mm.yaml +0 -12
- data/lib/zucker/1/desc/regexp2proc.yaml +0 -13
- data/lib/zucker/1/desc/sandbox.yaml +0 -14
- data/lib/zucker/1/desc/square_brackets_for.yaml +0 -23
- data/lib/zucker/1/desc/string.yaml +0 -13
- data/lib/zucker/1/desc/unary.yaml +0 -15
- data/lib/zucker/1/desc/union.yaml +0 -11
- data/lib/zucker/1/doc/meta.yaml +0 -4
- data/lib/zucker/1/doc/zucker_doc.html +0 -1286
- data/lib/zucker/1/doc/zucker_doc.rb +0 -493
- data/lib/zucker/1/spec/D_spec.rb +0 -27
- data/lib/zucker/1/spec/aliases_spec.rb +0 -34
- data/lib/zucker/1/spec/array2proc_spec.rb +0 -8
- data/lib/zucker/1/spec/array_spec.rb +0 -23
- data/lib/zucker/1/spec/binding_spec.rb +0 -6
- data/lib/zucker/1/spec/blank_spec.rb +0 -20
- data/lib/zucker/1/spec/class2proc_spec.rb +0 -9
- data/lib/zucker/1/spec/egonil_spec.rb +0 -30
- data/lib/zucker/1/spec/enumerable_spec.rb +0 -8
- data/lib/zucker/1/spec/hash2proc_spec.rb +0 -12
- data/lib/zucker/1/spec/hash_spec.rb +0 -10
- data/lib/zucker/1/spec/iterate_spec.rb +0 -54
- data/lib/zucker/1/spec/ivars_spec.rb +0 -20
- data/lib/zucker/1/spec/kernel_spec.rb +0 -34
- data/lib/zucker/1/spec/mcopy_spec.rb +0 -13
- data/lib/zucker/1/spec/mm_spec.rb +0 -6
- data/lib/zucker/1/spec/regexp2proc_spec.rb +0 -9
- data/lib/zucker/1/spec/sandbox_spec.rb +0 -7
- data/lib/zucker/1/spec/square_brackets_for_spec.rb +0 -59
- data/lib/zucker/1/spec/string_spec.rb +0 -29
- data/lib/zucker/1/spec/unary_spec.rb +0 -26
- data/lib/zucker/1/spec/union_spec.rb +0 -13
- data/lib/zucker/2/desc/D.yaml +0 -23
- data/lib/zucker/2/desc/aliases.yaml +0 -16
- data/lib/zucker/2/desc/array.yaml +0 -14
- data/lib/zucker/2/desc/array2proc.yaml +0 -17
- data/lib/zucker/2/desc/binding.yaml +0 -10
- data/lib/zucker/2/desc/blank.yaml +0 -10
- data/lib/zucker/2/desc/class2proc.yaml +0 -12
- data/lib/zucker/2/desc/egonil.yaml +0 -17
- data/lib/zucker/2/desc/enumerable.yaml +0 -11
- data/lib/zucker/2/desc/hash.yaml +0 -14
- data/lib/zucker/2/desc/hash2proc.yaml +0 -11
- data/lib/zucker/2/desc/info.yaml +0 -12
- data/lib/zucker/2/desc/iterate.yaml +0 -17
- data/lib/zucker/2/desc/ivars.yaml +0 -20
- data/lib/zucker/2/desc/kernel.yaml +0 -13
- data/lib/zucker/2/desc/mcopy.yaml +0 -12
- data/lib/zucker/2/desc/mm.yaml +0 -12
- data/lib/zucker/2/desc/regexp2proc.yaml +0 -13
- data/lib/zucker/2/desc/sandbox.yaml +0 -19
- data/lib/zucker/2/desc/square_brackets_for.yaml +0 -23
- data/lib/zucker/2/desc/string.yaml +0 -13
- data/lib/zucker/2/desc/unary.yaml +0 -15
- data/lib/zucker/2/desc/union.yaml +0 -11
- data/lib/zucker/2/doc/zucker_doc.html +0 -1494
- data/lib/zucker/2/doc/zucker_doc.rb +0 -498
- data/lib/zucker/2/spec/D_spec.rb +0 -35
- data/lib/zucker/2/spec/aliases_spec.rb +0 -13
- data/lib/zucker/2/spec/array2proc_spec.rb +0 -12
- data/lib/zucker/2/spec/array_spec.rb +0 -23
- data/lib/zucker/2/spec/binding_spec.rb +0 -8
- data/lib/zucker/2/spec/blank_spec.rb +0 -20
- data/lib/zucker/2/spec/class2proc_spec.rb +0 -9
- data/lib/zucker/2/spec/egonil_spec.rb +0 -30
- data/lib/zucker/2/spec/enumerable_spec.rb +0 -8
- data/lib/zucker/2/spec/hash2proc_spec.rb +0 -12
- data/lib/zucker/2/spec/hash_spec.rb +0 -17
- data/lib/zucker/2/spec/info_spec.rb +0 -8
- data/lib/zucker/2/spec/iterate_spec.rb +0 -54
- data/lib/zucker/2/spec/ivars_spec.rb +0 -20
- data/lib/zucker/2/spec/kernel_spec.rb +0 -28
- data/lib/zucker/2/spec/mcopy_spec.rb +0 -13
- data/lib/zucker/2/spec/mm_spec.rb +0 -8
- data/lib/zucker/2/spec/regexp2proc_spec.rb +0 -9
- data/lib/zucker/2/spec/sandbox_spec.rb +0 -26
- data/lib/zucker/2/spec/spec_helper.rb +0 -18
- data/lib/zucker/2/spec/square_brackets_for_spec.rb +0 -59
- data/lib/zucker/2/spec/string_spec.rb +0 -29
- data/lib/zucker/2/spec/unary_spec.rb +0 -26
- data/lib/zucker/2/spec/union_spec.rb +0 -15
- data/lib/zucker/desc/D.yaml +0 -23
- data/lib/zucker/desc/aliases.yaml +0 -16
- data/lib/zucker/desc/array.yaml +0 -14
- data/lib/zucker/desc/array2proc.yaml +0 -17
- data/lib/zucker/desc/binding.yaml +0 -10
- data/lib/zucker/desc/blank.yaml +0 -10
- data/lib/zucker/desc/class2proc.yaml +0 -12
- data/lib/zucker/desc/egonil.yaml +0 -17
- data/lib/zucker/desc/enumerable.yaml +0 -11
- data/lib/zucker/desc/hash.yaml +0 -14
- data/lib/zucker/desc/hash2proc.yaml +0 -11
- data/lib/zucker/desc/info.yaml +0 -12
- data/lib/zucker/desc/iterate.yaml +0 -17
- data/lib/zucker/desc/ivars.yaml +0 -20
- data/lib/zucker/desc/kernel.yaml +0 -13
- data/lib/zucker/desc/mcopy.yaml +0 -12
- data/lib/zucker/desc/mm.yaml +0 -12
- data/lib/zucker/desc/regexp2proc.yaml +0 -13
- data/lib/zucker/desc/sandbox.yaml +0 -19
- data/lib/zucker/desc/square_brackets_for.yaml +0 -23
- data/lib/zucker/desc/string.yaml +0 -13
- data/lib/zucker/desc/unary.yaml +0 -15
- data/lib/zucker/desc/union.yaml +0 -11
- data/lib/zucker/doc/zucker_doc.html +0 -1494
- data/lib/zucker/doc/zucker_doc.rb +0 -498
- data/lib/zucker/edge/ideas/args.rb +0 -22
- data/lib/zucker/edge/ideas/args.yaml +0 -19
- data/lib/zucker/edge/ideas/args_spec.rb +0 -19
- data/lib/zucker/edge/ideas/clone_deep.rb +0 -21
- data/lib/zucker/edge/ideas/clone_deep_spec.rb +0 -12
- data/lib/zucker/edge/ideas/dclone.yaml +0 -12
- data/lib/zucker/edge/ideas/hash.rb +0 -18
- data/lib/zucker/edge/ideas/require_directory.rb +0 -6
- data/lib/zucker/spec/D_spec.rb +0 -35
- data/lib/zucker/spec/aliases_spec.rb +0 -13
- data/lib/zucker/spec/array2proc_spec.rb +0 -12
- data/lib/zucker/spec/array_spec.rb +0 -23
- data/lib/zucker/spec/binding_spec.rb +0 -8
- data/lib/zucker/spec/blank_spec.rb +0 -20
- data/lib/zucker/spec/class2proc_spec.rb +0 -9
- data/lib/zucker/spec/egonil_spec.rb +0 -30
- data/lib/zucker/spec/enumerable_spec.rb +0 -8
- data/lib/zucker/spec/hash2proc_spec.rb +0 -12
- data/lib/zucker/spec/hash_spec.rb +0 -17
- data/lib/zucker/spec/info_spec.rb +0 -8
- data/lib/zucker/spec/iterate_spec.rb +0 -54
- data/lib/zucker/spec/ivars_spec.rb +0 -20
- data/lib/zucker/spec/kernel_spec.rb +0 -28
- data/lib/zucker/spec/mcopy_spec.rb +0 -13
- data/lib/zucker/spec/mm_spec.rb +0 -8
- data/lib/zucker/spec/regexp2proc_spec.rb +0 -9
- data/lib/zucker/spec/sandbox_spec.rb +0 -26
- data/lib/zucker/spec/spec_helper.rb +0 -18
- data/lib/zucker/spec/square_brackets_for_spec.rb +0 -59
- data/lib/zucker/spec/string_spec.rb +0 -29
- data/lib/zucker/spec/unary_spec.rb +0 -26
- data/lib/zucker/spec/union_spec.rb +0 -15
data/CHANGELOG
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
2010-08-14 | Zucker 3
|
2
|
+
* added tap cube
|
3
|
+
* added Object#not
|
4
|
+
* added alias_for for an alternative alias syntax
|
5
|
+
* added String#constantize (improved AS version)
|
6
|
+
* improved Info module
|
7
|
+
* made Array#sum Rails compatibile
|
8
|
+
* improved docs
|
9
|
+
* changed directory layout (no changes for requiring)
|
10
|
+
* more small changes
|
11
|
+
|
12
|
+
|
1
13
|
2010-08-08 | Zucker 2
|
2
14
|
* added info cube
|
3
15
|
* added chaining for array2proc
|
data/README
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
See http://rubyzucker.info
|
1
|
+
See http://rubyzucker.info or doc/zucker_doc.html
|
2
|
+
|
3
|
+
Please see the github wiki page, for discussion and contributing: http://wiki.github.com/janlelis/zucker
|
2
4
|
|
3
5
|
Copyright (c) 2010 Jan Lelis, http://rbjl.net, released under the MIT license
|
4
6
|
|
7
|
+
J-_-L
|
data/Rakefile
CHANGED
@@ -3,28 +3,38 @@ require 'rake'
|
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
require 'spec/rake/spectask'
|
5
5
|
|
6
|
+
if RUBY_VERSION >= '1.9.2'
|
7
|
+
require_relative 'lib/zucker'
|
8
|
+
else
|
9
|
+
require 'lib/zucker'
|
10
|
+
end
|
11
|
+
|
6
12
|
desc 'Build documentation'
|
7
13
|
task 'doc' do
|
8
|
-
zucker_path =
|
14
|
+
zucker_path = Rake.application.find_rakefile_location[1]
|
9
15
|
ruby File.join(zucker_path, 'doc/zucker_doc.rb'), zucker_path
|
10
16
|
end
|
11
17
|
|
18
|
+
task 'default' => 'spec'
|
12
19
|
Spec::Rake::SpecTask.new('spec') do |t|
|
13
|
-
t.spec_files = FileList['
|
20
|
+
t.spec_files = FileList['spec/*.rb']
|
14
21
|
end
|
15
22
|
|
16
23
|
# gem
|
17
24
|
PKG_FILES = FileList[ '[a-zA-Z]*', 'lib/**/*' ]
|
18
25
|
spec = Gem::Specification.new do |s|
|
19
26
|
s.name = 'zucker'
|
20
|
-
s.version =
|
21
|
-
s.date =
|
22
|
-
s.authors = ['Jan Lelis']
|
27
|
+
s.version = Zucker::VERSION
|
28
|
+
s.date = Zucker::DATE
|
29
|
+
s.authors = ['Based on the thoughts of many people ;)', 'Jan Lelis']
|
23
30
|
s.email = 'mail@janlelis.de'
|
24
|
-
s.summary =
|
31
|
+
s.summary = "Make your Ruby code even sweeter with syntactic sugar :)
|
32
|
+
Adds lots of little helpers that you never want to miss again.
|
33
|
+
See http://rubyzucker.info"
|
25
34
|
s.homepage = 'http://rubyzucker.info'
|
26
35
|
s.files = PKG_FILES.to_a
|
27
|
-
s.require_paths = ["
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.required_ruby_version = '>= 1.8.7' # 1.9 recommended
|
28
38
|
end
|
29
39
|
|
30
40
|
Rake::GemPackageTask.new(spec) do |pkg|
|
data/lib/zucker.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
module Zucker
|
2
|
+
VERSION = '3'
|
3
|
+
DATE = '2010-08-14'
|
4
|
+
end
|
5
|
+
|
6
|
+
# nothing further is done here
|
2
7
|
# to use zucker:
|
3
8
|
|
4
9
|
# require 'zucker/default'
|
@@ -9,3 +14,4 @@
|
|
9
14
|
|
10
15
|
# or cherry-pick the cubes you want ;)
|
11
16
|
|
17
|
+
# eg. require 'zucker/egonil'
|
data/lib/zucker/2/all.rb
CHANGED
data/lib/zucker/2/debug.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'zucker/D'
|
2
|
-
require 'zucker/mm'
|
3
|
-
require 'zucker/binding'
|
1
|
+
require 'zucker/2/D'
|
2
|
+
require 'zucker/2/mm'
|
3
|
+
require 'zucker/2/binding'
|
4
4
|
|
data/lib/zucker/2/default.rb
CHANGED
data/lib/zucker/3/D.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Kernel
|
2
|
+
def D(*args, &block)
|
3
|
+
if args.empty?
|
4
|
+
tap{
|
5
|
+
if block_given?
|
6
|
+
puts yield self
|
7
|
+
else
|
8
|
+
puts self.inspect
|
9
|
+
end
|
10
|
+
}
|
11
|
+
else
|
12
|
+
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!"
|
13
|
+
# eval ...
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# J-_-L
|
19
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
def alias_for(m, *aliases)
|
2
|
+
aliases.each{ |a|
|
3
|
+
class_eval "alias #{a} #{m}"
|
4
|
+
}
|
5
|
+
end
|
6
|
+
alias aliases_for alias_for
|
7
|
+
|
8
|
+
class Module
|
9
|
+
def alias_method_for(m, *alias_methods)
|
10
|
+
alias_methods.each{ |a|
|
11
|
+
class_eval do
|
12
|
+
alias_method a.to_sym, m.to_sym
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
alias alias_methods_for alias_method_for
|
17
|
+
end
|
18
|
+
|
19
|
+
# J-_-L
|
@@ -0,0 +1,28 @@
|
|
1
|
+
alias is_an? is_a?
|
2
|
+
|
3
|
+
module Enumerable
|
4
|
+
alias with zip
|
5
|
+
alias % zip
|
6
|
+
end
|
7
|
+
|
8
|
+
class Array
|
9
|
+
alias ** product
|
10
|
+
end
|
11
|
+
|
12
|
+
class Hash
|
13
|
+
alias + merge
|
14
|
+
end
|
15
|
+
|
16
|
+
class Binding
|
17
|
+
#alias [] eval
|
18
|
+
def [](expr)
|
19
|
+
self.eval "#{expr}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# constants - who would use these in real-world code for other things?
|
24
|
+
Infinity = 1.0 / 0.0 # or 2*Float::MAX
|
25
|
+
NaN = 0.0 / 0.0
|
26
|
+
|
27
|
+
# J-_-L
|
28
|
+
|
data/lib/zucker/3/all.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Array
|
2
|
+
def ^(other) # TODO: more efficient
|
3
|
+
(self - other) +
|
4
|
+
(other - self)
|
5
|
+
end
|
6
|
+
|
7
|
+
# can take an argument & block to be Rails compatible
|
8
|
+
def sum(identity = 0, &block)
|
9
|
+
# inject(:+)
|
10
|
+
if block_given?
|
11
|
+
map(&block).sum( identity )
|
12
|
+
else
|
13
|
+
inject(:+) || identity
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def chrs
|
18
|
+
self.pack 'C*'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# J-_-L
|
23
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Binding
|
2
|
+
def inspect
|
3
|
+
put_vars = lambda { |array|
|
4
|
+
if array.empty?
|
5
|
+
' - none'
|
6
|
+
else
|
7
|
+
array.map{|e| " - #{e}: #{ self.eval '#{e}'}"}*"\n"
|
8
|
+
end
|
9
|
+
}
|
10
|
+
|
11
|
+
"#{self.to_s}
|
12
|
+
local vars
|
13
|
+
#{ put_vars[ self.eval 'local_variables' ] }
|
14
|
+
(instance vars)
|
15
|
+
#{ put_vars[ self.eval 'instance_variables' ] }
|
16
|
+
self
|
17
|
+
- #{self.eval 'self'}
|
18
|
+
block_given?
|
19
|
+
- #{self.eval 'block_given?'}"
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# J-_-L
|
25
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Object
|
2
|
+
def blank?
|
3
|
+
if respond_to? :empty? then empty? else !self end
|
4
|
+
end
|
5
|
+
|
6
|
+
def present?
|
7
|
+
!blank?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
{ # what to do # for which classes
|
13
|
+
lambda{ true } => [FalseClass, NilClass],
|
14
|
+
lambda{ false } => [TrueClass, Numeric],
|
15
|
+
lambda{ empty? } => [Array, Hash],
|
16
|
+
lambda{ self !~ /\S/ } => [String],
|
17
|
+
lambda{ self == // } => [Regexp],
|
18
|
+
|
19
|
+
}.each{ |action, klass_array|
|
20
|
+
klass_array.each{ |klass|
|
21
|
+
klass.send :define_method, :blank?, &action
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
# J-_-L
|
26
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'zucker'
|
2
|
+
|
3
|
+
# default
|
4
|
+
zucker = %w|
|
5
|
+
alias_for
|
6
|
+
aliases
|
7
|
+
array
|
8
|
+
array2proc
|
9
|
+
blank
|
10
|
+
class2proc
|
11
|
+
egonil
|
12
|
+
enumerable
|
13
|
+
hash
|
14
|
+
hash2proc
|
15
|
+
info
|
16
|
+
iterate
|
17
|
+
ivars
|
18
|
+
kernel
|
19
|
+
mcopy
|
20
|
+
not
|
21
|
+
regexp2proc
|
22
|
+
sandbox
|
23
|
+
square_brackets_for
|
24
|
+
string
|
25
|
+
tap
|
26
|
+
unary
|
27
|
+
union
|
28
|
+
|
|
29
|
+
|
30
|
+
# remove 1.9 if 1.8
|
31
|
+
if RUBY_VERSION < '1.9'
|
32
|
+
zucker -= %w|not tap union|
|
33
|
+
end
|
34
|
+
|
35
|
+
zucker.each{|rb| require File.join( 'zucker', '3', rb )}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Hash
|
2
|
+
def self.zip(keys,values)
|
3
|
+
Hash[ *keys.zip( values ).flatten ]
|
4
|
+
end
|
5
|
+
|
6
|
+
def <<(other)
|
7
|
+
case
|
8
|
+
when other.is_a?(Hash)
|
9
|
+
merge! other
|
10
|
+
when other.is_a?(Enumerable) || other.respond_to?(:to_splat)
|
11
|
+
merge! Hash[*other]
|
12
|
+
else
|
13
|
+
raise TypeError, 'can only append other Hashs and Enumerables (or Classes that implement to_splat)'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# J-_-L
|
19
|
+
|
@@ -0,0 +1,167 @@
|
|
1
|
+
module Info
|
2
|
+
class << Info
|
3
|
+
# hash like access
|
4
|
+
def [](what)
|
5
|
+
send what
|
6
|
+
end
|
7
|
+
|
8
|
+
# list available info methods
|
9
|
+
def list
|
10
|
+
singleton_methods - [:[], :list, '[]', 'list']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module_function
|
15
|
+
|
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
|
+
# input
|
26
|
+
def last_input_file
|
27
|
+
$FILENAME
|
28
|
+
end
|
29
|
+
|
30
|
+
def last_input_line_number
|
31
|
+
$.
|
32
|
+
end
|
33
|
+
|
34
|
+
def last_input
|
35
|
+
$_
|
36
|
+
end
|
37
|
+
|
38
|
+
# program
|
39
|
+
def program_name
|
40
|
+
$0
|
41
|
+
end
|
42
|
+
|
43
|
+
def program_arguments
|
44
|
+
$:
|
45
|
+
end
|
46
|
+
|
47
|
+
def loaded_programs
|
48
|
+
$"
|
49
|
+
end
|
50
|
+
|
51
|
+
def program_data
|
52
|
+
::DATA
|
53
|
+
end
|
54
|
+
|
55
|
+
def child_program_status
|
56
|
+
$CHILD_STATUS
|
57
|
+
end
|
58
|
+
|
59
|
+
# system info
|
60
|
+
def environment
|
61
|
+
::ENV
|
62
|
+
end
|
63
|
+
alias env environment
|
64
|
+
|
65
|
+
def working_directory
|
66
|
+
Dir.pwd
|
67
|
+
end
|
68
|
+
|
69
|
+
def platform
|
70
|
+
::RUBY_PLATFORM
|
71
|
+
end
|
72
|
+
|
73
|
+
def process_id
|
74
|
+
$$
|
75
|
+
end
|
76
|
+
|
77
|
+
def load_path
|
78
|
+
$:
|
79
|
+
end
|
80
|
+
|
81
|
+
# current
|
82
|
+
def current_line
|
83
|
+
__LINE__
|
84
|
+
end
|
85
|
+
|
86
|
+
def current_method # 1.9
|
87
|
+
__method__
|
88
|
+
end
|
89
|
+
|
90
|
+
def current_callstack
|
91
|
+
caller
|
92
|
+
end
|
93
|
+
|
94
|
+
# dealing with strings
|
95
|
+
def gets_separator
|
96
|
+
$/
|
97
|
+
end
|
98
|
+
|
99
|
+
def join_separator
|
100
|
+
$,
|
101
|
+
end
|
102
|
+
|
103
|
+
def print_separator
|
104
|
+
$,
|
105
|
+
end
|
106
|
+
|
107
|
+
def split_separator
|
108
|
+
$;
|
109
|
+
end
|
110
|
+
|
111
|
+
# misc
|
112
|
+
def security_level
|
113
|
+
$SAFE
|
114
|
+
end
|
115
|
+
|
116
|
+
def warnings_activated?
|
117
|
+
$VERBOSE
|
118
|
+
end
|
119
|
+
|
120
|
+
def debug_activated?
|
121
|
+
$DEBUG
|
122
|
+
end
|
123
|
+
|
124
|
+
def last_exception
|
125
|
+
$!
|
126
|
+
end
|
127
|
+
|
128
|
+
# defined objects
|
129
|
+
def global_variables
|
130
|
+
Object.send :global_variables
|
131
|
+
end
|
132
|
+
|
133
|
+
def global_constants
|
134
|
+
Object.constants
|
135
|
+
end
|
136
|
+
|
137
|
+
# encoding (1.9)
|
138
|
+
def source_encoding
|
139
|
+
__ENCODING__
|
140
|
+
end
|
141
|
+
|
142
|
+
def external_encoding
|
143
|
+
Encoding.default_external
|
144
|
+
end
|
145
|
+
|
146
|
+
def internal_encoding
|
147
|
+
Encoding.default_internal
|
148
|
+
end
|
149
|
+
|
150
|
+
# ruby version info
|
151
|
+
def ruby_version
|
152
|
+
::RUBY_VERSION
|
153
|
+
end
|
154
|
+
|
155
|
+
def ruby_patchlevel
|
156
|
+
::RUBY_PATCHLEVEL
|
157
|
+
end
|
158
|
+
|
159
|
+
def ruby_description
|
160
|
+
::RUBY_DESCRIPTION
|
161
|
+
end
|
162
|
+
|
163
|
+
def ruby_release_date
|
164
|
+
::RUBY_RELEASE_DATE
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|