zucker 1 → 2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/Rakefile +14 -4
- data/lib/zucker.rb +0 -4
- data/lib/zucker/2/D.rb +19 -0
- data/lib/zucker/2/aliases.rb +28 -0
- data/lib/zucker/2/all.rb +6 -0
- data/lib/zucker/2/array.rb +17 -0
- data/lib/zucker/2/array2proc.rb +16 -0
- data/lib/zucker/2/binding.rb +25 -0
- data/lib/zucker/2/blank.rb +26 -0
- data/lib/zucker/2/class2proc.rb +10 -0
- data/lib/zucker/2/debug.rb +4 -0
- data/lib/zucker/2/default.rb +25 -0
- data/lib/zucker/2/desc/D.yaml +23 -0
- data/lib/zucker/2/desc/aliases.yaml +16 -0
- data/lib/zucker/2/desc/array.yaml +14 -0
- data/lib/zucker/2/desc/array2proc.yaml +17 -0
- data/lib/zucker/2/desc/binding.yaml +10 -0
- data/lib/zucker/2/desc/blank.yaml +10 -0
- data/lib/zucker/2/desc/class2proc.yaml +12 -0
- data/lib/zucker/2/desc/egonil.yaml +17 -0
- data/lib/zucker/2/desc/enumerable.yaml +11 -0
- data/lib/zucker/2/desc/hash.yaml +14 -0
- data/lib/zucker/2/desc/hash2proc.yaml +11 -0
- data/lib/zucker/2/desc/info.yaml +12 -0
- data/lib/zucker/2/desc/iterate.yaml +17 -0
- data/lib/zucker/2/desc/ivars.yaml +20 -0
- data/lib/zucker/2/desc/kernel.yaml +13 -0
- data/lib/zucker/2/desc/mcopy.yaml +12 -0
- data/lib/zucker/2/desc/mm.yaml +12 -0
- data/lib/zucker/2/desc/regexp2proc.yaml +13 -0
- data/lib/zucker/2/desc/sandbox.yaml +19 -0
- data/lib/zucker/2/desc/square_brackets_for.yaml +23 -0
- data/lib/zucker/2/desc/string.yaml +13 -0
- data/lib/zucker/2/desc/unary.yaml +15 -0
- data/lib/zucker/2/desc/union.yaml +11 -0
- data/lib/zucker/2/doc/zucker_doc.html +1494 -0
- data/lib/zucker/2/doc/zucker_doc.rb +498 -0
- data/lib/zucker/2/egonil.rb +14 -0
- data/lib/zucker/2/enumerable.rb +12 -0
- data/lib/zucker/2/hash.rb +19 -0
- data/lib/zucker/2/hash2proc.rb +14 -0
- data/lib/zucker/2/info.rb +164 -0
- data/lib/zucker/2/iterate.rb +23 -0
- data/lib/zucker/2/ivars.rb +26 -0
- data/lib/zucker/2/kernel.rb +18 -0
- data/lib/zucker/2/mcopy.rb +9 -0
- data/lib/zucker/2/mm.rb +31 -0
- data/lib/zucker/2/regexp2proc.rb +10 -0
- data/lib/zucker/2/sandbox.rb +19 -0
- data/lib/zucker/2/spec/D_spec.rb +35 -0
- data/lib/zucker/2/spec/aliases_spec.rb +13 -0
- data/lib/zucker/2/spec/array2proc_spec.rb +12 -0
- data/lib/zucker/2/spec/array_spec.rb +23 -0
- data/lib/zucker/2/spec/binding_spec.rb +8 -0
- data/lib/zucker/2/spec/blank_spec.rb +20 -0
- data/lib/zucker/2/spec/class2proc_spec.rb +9 -0
- data/lib/zucker/2/spec/egonil_spec.rb +30 -0
- data/lib/zucker/2/spec/enumerable_spec.rb +8 -0
- data/lib/zucker/2/spec/hash2proc_spec.rb +12 -0
- data/lib/zucker/2/spec/hash_spec.rb +17 -0
- data/lib/zucker/2/spec/info_spec.rb +8 -0
- data/lib/zucker/2/spec/iterate_spec.rb +54 -0
- data/lib/zucker/2/spec/ivars_spec.rb +20 -0
- data/lib/zucker/2/spec/kernel_spec.rb +28 -0
- data/lib/zucker/2/spec/mcopy_spec.rb +13 -0
- data/lib/zucker/2/spec/mm_spec.rb +8 -0
- data/lib/zucker/2/spec/regexp2proc_spec.rb +9 -0
- data/lib/zucker/2/spec/sandbox_spec.rb +26 -0
- data/lib/zucker/2/spec/spec_helper.rb +18 -0
- data/lib/zucker/2/spec/square_brackets_for_spec.rb +59 -0
- data/lib/zucker/2/spec/string_spec.rb +29 -0
- data/lib/zucker/2/spec/unary_spec.rb +26 -0
- data/lib/zucker/2/spec/union_spec.rb +15 -0
- data/lib/zucker/2/square_brackets_for.rb +20 -0
- data/lib/zucker/2/string.rb +25 -0
- data/lib/zucker/2/unary.rb +22 -0
- data/lib/zucker/2/union.rb +14 -0
- data/lib/zucker/all.rb +2 -2
- data/lib/zucker/array2proc.rb +7 -1
- data/lib/zucker/debug.rb +3 -3
- data/lib/zucker/default.rb +1 -1
- data/lib/zucker/desc/D.yaml +1 -1
- data/lib/zucker/desc/array.yaml +1 -1
- data/lib/zucker/desc/array2proc.yaml +5 -1
- data/lib/zucker/desc/binding.yaml +2 -2
- data/lib/zucker/desc/blank.yaml +1 -3
- data/lib/zucker/desc/egonil.yaml +1 -1
- data/lib/zucker/desc/enumerable.yaml +1 -1
- data/lib/zucker/desc/hash.yaml +4 -2
- data/lib/zucker/desc/info.yaml +12 -0
- data/lib/zucker/desc/kernel.yaml +2 -2
- data/lib/zucker/desc/mm.yaml +3 -3
- data/lib/zucker/desc/regexp2proc.yaml +1 -1
- data/lib/zucker/desc/sandbox.yaml +6 -1
- data/lib/zucker/desc/string.yaml +1 -1
- data/lib/zucker/desc/unary.yaml +2 -2
- data/lib/zucker/desc/union.yaml +1 -1
- data/lib/zucker/doc/zucker_doc.html +441 -233
- data/lib/zucker/doc/zucker_doc.rb +32 -27
- data/lib/zucker/hash.rb +3 -3
- data/lib/zucker/info.rb +164 -0
- data/lib/zucker/ivars.rb +1 -1
- data/lib/zucker/kernel.rb +2 -4
- data/lib/zucker/sandbox.rb +7 -3
- data/lib/zucker/spec/D_spec.rb +15 -7
- data/lib/zucker/spec/aliases_spec.rb +3 -24
- data/lib/zucker/spec/array2proc_spec.rb +5 -1
- data/lib/zucker/spec/array_spec.rb +1 -1
- data/lib/zucker/spec/binding_spec.rb +4 -2
- data/lib/zucker/spec/blank_spec.rb +1 -1
- data/lib/zucker/spec/class2proc_spec.rb +1 -1
- data/lib/zucker/spec/egonil_spec.rb +1 -1
- data/lib/zucker/spec/enumerable_spec.rb +1 -1
- data/lib/zucker/spec/hash2proc_spec.rb +1 -1
- data/lib/zucker/spec/hash_spec.rb +10 -3
- data/lib/zucker/spec/info_spec.rb +8 -0
- data/lib/zucker/spec/iterate_spec.rb +1 -1
- data/lib/zucker/spec/ivars_spec.rb +1 -1
- data/lib/zucker/spec/kernel_spec.rb +1 -7
- data/lib/zucker/spec/mcopy_spec.rb +1 -1
- data/lib/zucker/spec/mm_spec.rb +4 -2
- data/lib/zucker/spec/regexp2proc_spec.rb +1 -1
- data/lib/zucker/spec/sandbox_spec.rb +22 -3
- data/lib/zucker/spec/spec_helper.rb +18 -0
- data/lib/zucker/spec/square_brackets_for_spec.rb +1 -1
- data/lib/zucker/spec/string_spec.rb +7 -7
- data/lib/zucker/spec/unary_spec.rb +1 -1
- data/lib/zucker/spec/union_spec.rb +8 -6
- metadata +207 -131
- data/lib/zucker/doc/meta.yaml +0 -4
data/CHANGELOG
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
2010-08-08 | Zucker 2
|
2
|
+
* added info cube
|
3
|
+
* added chaining for array2proc
|
4
|
+
* fixed Hash.zip
|
5
|
+
* fixed instance_variables_from binding for 1.9
|
6
|
+
* more specs
|
7
|
+
|
8
|
+
|
9
|
+
2010-08-06 | Zucker 1
|
10
|
+
* initial release
|
11
|
+
|
12
|
+
|
13
|
+
2010-08-05 | Zucker 0
|
14
|
+
* pre-release for rug-b talk
|
data/Rakefile
CHANGED
@@ -1,17 +1,27 @@
|
|
1
1
|
require 'rake'
|
2
|
+
# require 'rubygems'
|
2
3
|
require 'rake/gempackagetask'
|
3
|
-
require 'rubygems'
|
4
4
|
require 'spec/rake/spectask'
|
5
5
|
|
6
|
+
desc 'Build documentation'
|
7
|
+
task 'doc' do
|
8
|
+
zucker_path = "#{ Rake.application.find_rakefile_location[1] }/lib/zucker"
|
9
|
+
ruby File.join(zucker_path, 'doc/zucker_doc.rb'), zucker_path
|
10
|
+
end
|
11
|
+
|
12
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
13
|
+
t.spec_files = FileList['lib/zucker/spec/**/*.rb']
|
14
|
+
end
|
15
|
+
|
6
16
|
# gem
|
7
17
|
PKG_FILES = FileList[ '[a-zA-Z]*', 'lib/**/*' ]
|
8
18
|
spec = Gem::Specification.new do |s|
|
9
19
|
s.name = 'zucker'
|
10
|
-
s.version = '
|
11
|
-
s.date = '2010-08-
|
20
|
+
s.version = '2'
|
21
|
+
s.date = '2010-08-08'
|
12
22
|
s.authors = ['Jan Lelis']
|
13
23
|
s.email = 'mail@janlelis.de'
|
14
|
-
s.summary = '
|
24
|
+
s.summary = 'Make your Ruby code even sweeter with this syntacitcal sugar: http://rubyzucker.info :)'
|
15
25
|
s.homepage = 'http://rubyzucker.info'
|
16
26
|
s.files = PKG_FILES.to_a
|
17
27
|
s.require_paths = [".","lib"]
|
data/lib/zucker.rb
CHANGED
data/lib/zucker/2/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,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/2/all.rb
ADDED
@@ -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,25 @@
|
|
1
|
+
# default
|
2
|
+
zucker = %w|
|
3
|
+
aliases
|
4
|
+
array
|
5
|
+
array2proc
|
6
|
+
blank
|
7
|
+
class2proc
|
8
|
+
egonil
|
9
|
+
enumerable
|
10
|
+
hash
|
11
|
+
hash2proc
|
12
|
+
iterate
|
13
|
+
ivars
|
14
|
+
kernel
|
15
|
+
mcopy
|
16
|
+
regexp2proc
|
17
|
+
sandbox
|
18
|
+
square_brackets_for
|
19
|
+
string
|
20
|
+
unary
|
21
|
+
union
|
22
|
+
|
|
23
|
+
|
24
|
+
zucker.each{|rb| require "zucker/#{rb}"}
|
25
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
D:
|
2
|
+
summary: Easy debug printing with the ⇧p⇧ alternative ⇧.D⇧. It outputs to stdout and returns ⇧self⇧. Accepts a block.
|
3
|
+
methods:
|
4
|
+
Object#D: |
|
5
|
+
some.D.methods.D.noone.D.knows.D
|
6
|
+
# ...outputs 4 lines with the inspected objects
|
7
|
+
# => (result)
|
8
|
+
|
9
|
+
21+Math.sin(42).D
|
10
|
+
# outputs -0.916521547915634
|
11
|
+
# => 20.0834784520844
|
12
|
+
|
13
|
+
name = 'Earth'
|
14
|
+
'Hello ' + name.D{|e| "The length is: #{e.size}"}
|
15
|
+
# outputs "The length is: 5"
|
16
|
+
# => 'Hello Earth'
|
17
|
+
package: debug
|
18
|
+
info:
|
19
|
+
- "This is inspired by the funny →⇧.tap⇧ method→http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions→."
|
20
|
+
versions:
|
21
|
+
- 1.9
|
22
|
+
- 1.8
|
23
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
aliases:
|
2
|
+
summary: Some convenient aliases (and constants) for existing methods.
|
3
|
+
package: default
|
4
|
+
methods:
|
5
|
+
Object#is_an?: Object.is_a?
|
6
|
+
Enumerable#with: Enumerable#zip
|
7
|
+
Enumerable#%: Enumerable#zip
|
8
|
+
Array#**: Array#product
|
9
|
+
Hash#+: Hash#merge
|
10
|
+
Binding#[]: Binding#eval
|
11
|
+
Infinity: 1.0 / 0.0
|
12
|
+
NaN: 0.0 / 0.0
|
13
|
+
versions:
|
14
|
+
- 1.9
|
15
|
+
- 1.8
|
16
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
array:
|
2
|
+
summary: Methods one could miss for ⇧Array⇧.
|
3
|
+
why:
|
4
|
+
- ⇧Array⇧ has ⇧&⇧ and ⇧|⇧, but why does it not have ⇧^⇧?
|
5
|
+
- ⇧sum⇧ is just an alias for ⇧inject(:+)⇧, but it is needed pretty often..
|
6
|
+
methods:
|
7
|
+
Array#^: "[1,2,3,4] ^ [3,4,5,6] # => [1,2,5,6]"
|
8
|
+
Array#sum: "[1,2,3,4,5].sum # => 15"
|
9
|
+
Array#chrs: "[72, 97, 108, 108, 111].chrs # => 'Hallo'"
|
10
|
+
package: default
|
11
|
+
versions:
|
12
|
+
- 1.9
|
13
|
+
- 1.8
|
14
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
array2proc:
|
2
|
+
summary: Calls the method named by the first paramenter and passes the other elements as paramaters.
|
3
|
+
why: When using ⇧Symbol#to_proc⇧, you often wish to pass parameters.
|
4
|
+
methods:
|
5
|
+
Array#to_proc: |
|
6
|
+
[1,2,3,4].map &[:*, 5] # => [5, 10, 15, 20]
|
7
|
+
# you can also chain them, if the first parameter is an Array
|
8
|
+
[1,2,3,4].map &[[:to_s, 2],[:+, 'b']] # => ["1b", "10b", "11b", "100b"]
|
9
|
+
info:
|
10
|
+
- Inspired by →this article→http://www.sanityinc.com/articles/adding-array-to-proc-to-ruby→.
|
11
|
+
- "More about →to_proc→http://rbjl.net/29-become-a-proc-star→."
|
12
|
+
- Chaining inspired by →eregon→http://github.com/eregon/Classes/blob/master/to_proc.rb→.
|
13
|
+
package: default
|
14
|
+
versions:
|
15
|
+
- 1.9
|
16
|
+
- 1.8
|
17
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class2proc:
|
2
|
+
summary: Creates a new instance of the class.
|
3
|
+
methods:
|
4
|
+
Class#to_proc: "[ [1,2],[3,5,6,7,3] ].map(&Set) # => [ Set[1,2], Set[5,6,7,3] ]"
|
5
|
+
package: default
|
6
|
+
info:
|
7
|
+
- Inspired by Ruby Facets.
|
8
|
+
- "More about →to_proc→http://rbjl.net/29-become-a-proc-star→."
|
9
|
+
versions:
|
10
|
+
- 1.9
|
11
|
+
- 1.8
|
12
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
egonil:
|
2
|
+
summary: Creates a block, where ⇧nil⇧ does not raise ⇧NoMethodError⇧s.
|
3
|
+
methods:
|
4
|
+
egonil, nn: |
|
5
|
+
egonil do
|
6
|
+
nil.some_methods.that[:do].not.exist
|
7
|
+
end # => nil
|
8
|
+
|
9
|
+
nn(5){ nil.some_methods.that[:do].not.exist }
|
10
|
+
# => 5
|
11
|
+
package: default
|
12
|
+
info:
|
13
|
+
- See →this post→http://rbjl.net/26-the-28-bytes-of-ruby-joy→ for more information and discussion.
|
14
|
+
versions:
|
15
|
+
- 1.9
|
16
|
+
- 1.8
|
17
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
hash:
|
2
|
+
summary: Some sugar for dealing with hashs.
|
3
|
+
methods:
|
4
|
+
Hash.zip: "Hash.zip [1,2,3], [4,5,6] # => {1 => 4, 2 => 5, 3 => 6}"
|
5
|
+
Hash#<<: |
|
6
|
+
{1 => 2} << [3, 4] # => { 1 => 2, 3 => 4 }
|
7
|
+
{1 => 2} << { 5=>6 } # => { 1 => 2, 5 => 6 }
|
8
|
+
package: default
|
9
|
+
info:
|
10
|
+
- Some of the operators are inspired by Ruby Facets.
|
11
|
+
versions:
|
12
|
+
- 1.9
|
13
|
+
- 1.8
|
14
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
hash2proc:
|
2
|
+
summary: Use a hash to apply procs to specific objects.
|
3
|
+
methods:
|
4
|
+
Hash#to_proc: "[1,2,3,4].map(&{\n2 => lambda {|e| e + 1000},\n4 => :to_s,\n}) # => [1, 1002, 3, '4']"
|
5
|
+
package: default
|
6
|
+
info:
|
7
|
+
- "More about →to_proc→http://rbjl.net/29-become-a-proc-star→."
|
8
|
+
versions:
|
9
|
+
- 1.9
|
10
|
+
- 1.8
|
11
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
info:
|
2
|
+
summary: Access environment information with the ⇧Info⇧ module.
|
3
|
+
why: "You don't need to remember in which global variable, constant or special method the information you are searching for is hidden."
|
4
|
+
methods:
|
5
|
+
Info: |
|
6
|
+
# see the source file for the list of accessors
|
7
|
+
# you could also add them to the global namespace with: include Info
|
8
|
+
package: default
|
9
|
+
versions:
|
10
|
+
- 1.9
|
11
|
+
- 1.8 (not all information)
|
12
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
iterate:
|
2
|
+
summary: Iterate over one or more collections.
|
3
|
+
why: "It's like ⇧.each⇧ with two differences: It feels more like a control structure and you can easily iterate over multiple objects."
|
4
|
+
methods:
|
5
|
+
iterate: |
|
6
|
+
iterate [1,2], [3,4,5] do |e,f|
|
7
|
+
puts "#{e},#{f}"
|
8
|
+
end
|
9
|
+
# outputs
|
10
|
+
# 1,3
|
11
|
+
# 2,4
|
12
|
+
# ,5
|
13
|
+
package: default
|
14
|
+
versions:
|
15
|
+
- 1.9
|
16
|
+
- 1.8
|
17
|
+
|