zucker 0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +4 -0
- data/Rakefile +23 -0
- data/lib/zucker.rb +10 -0
- data/lib/zucker/1/D.rb +19 -0
- data/lib/zucker/1/aliases.rb +28 -0
- data/lib/zucker/1/all.rb +6 -0
- data/lib/zucker/1/array.rb +17 -0
- data/lib/zucker/1/array2proc.rb +10 -0
- data/lib/zucker/1/binding.rb +25 -0
- data/lib/zucker/1/blank.rb +26 -0
- data/lib/zucker/1/class2proc.rb +10 -0
- data/lib/zucker/1/debug.rb +4 -0
- data/lib/zucker/1/default.rb +25 -0
- data/lib/zucker/1/descriptions/D.yaml +25 -0
- data/lib/zucker/1/descriptions/aliases.yaml +18 -0
- data/lib/zucker/1/descriptions/array.yaml +16 -0
- data/lib/zucker/1/descriptions/array2proc.yaml +15 -0
- data/lib/zucker/1/descriptions/binding.yaml +12 -0
- data/lib/zucker/1/descriptions/blank.yaml +14 -0
- data/lib/zucker/1/descriptions/class2proc.yaml +15 -0
- data/lib/zucker/1/descriptions/egonil.yaml +20 -0
- data/lib/zucker/1/descriptions/enumerable.yaml +13 -0
- data/lib/zucker/1/descriptions/hash.yaml +14 -0
- data/lib/zucker/1/descriptions/hash2proc.yaml +13 -0
- data/lib/zucker/1/descriptions/iterate.yaml +19 -0
- data/lib/zucker/1/descriptions/ivars.yaml +22 -0
- data/lib/zucker/1/descriptions/kernel.yaml +13 -0
- data/lib/zucker/1/descriptions/mcopy.yaml +14 -0
- data/lib/zucker/1/descriptions/mm.yaml +14 -0
- data/lib/zucker/1/descriptions/regexp2proc.yaml +15 -0
- data/lib/zucker/1/descriptions/sandbox.yaml +16 -0
- data/lib/zucker/1/descriptions/square_brackets_for.yaml +25 -0
- data/lib/zucker/1/descriptions/string.yaml +15 -0
- data/lib/zucker/1/descriptions/unary.yaml +15 -0
- data/lib/zucker/1/descriptions/union.yaml +11 -0
- data/lib/zucker/1/documentation/meta.yaml +4 -0
- data/lib/zucker/1/documentation/zucker_doc.html +1158 -0
- data/lib/zucker/1/documentation/zucker_doc.rb +369 -0
- data/lib/zucker/1/egonil.rb +14 -0
- data/lib/zucker/1/enumerable.rb +12 -0
- data/lib/zucker/1/hash.rb +19 -0
- data/lib/zucker/1/hash2proc.rb +12 -0
- data/lib/zucker/1/iterate.rb +23 -0
- data/lib/zucker/1/ivars.rb +26 -0
- data/lib/zucker/1/kernel.rb +20 -0
- data/lib/zucker/1/mcopy.rb +9 -0
- data/lib/zucker/1/mm.rb +31 -0
- data/lib/zucker/1/regexp2proc.rb +10 -0
- data/lib/zucker/1/sandbox.rb +15 -0
- data/lib/zucker/1/specification/D_spec.rb +27 -0
- data/lib/zucker/1/specification/aliases_spec.rb +34 -0
- data/lib/zucker/1/specification/array2proc_spec.rb +8 -0
- data/lib/zucker/1/specification/array_spec.rb +23 -0
- data/lib/zucker/1/specification/binding_spec.rb +6 -0
- data/lib/zucker/1/specification/blank_spec.rb +20 -0
- data/lib/zucker/1/specification/class2proc_spec.rb +9 -0
- data/lib/zucker/1/specification/egonil_spec.rb +30 -0
- data/lib/zucker/1/specification/enumerable_spec.rb +8 -0
- data/lib/zucker/1/specification/hash2proc_spec.rb +12 -0
- data/lib/zucker/1/specification/hash_spec.rb +10 -0
- data/lib/zucker/1/specification/iterate_spec.rb +54 -0
- data/lib/zucker/1/specification/ivars_spec.rb +20 -0
- data/lib/zucker/1/specification/kernel_spec.rb +34 -0
- data/lib/zucker/1/specification/mcopy_spec.rb +13 -0
- data/lib/zucker/1/specification/mm_spec.rb +6 -0
- data/lib/zucker/1/specification/regexp2proc_spec.rb +9 -0
- data/lib/zucker/1/specification/sandbox_spec.rb +7 -0
- data/lib/zucker/1/specification/square_brackets_for_spec.rb +59 -0
- data/lib/zucker/1/specification/string_spec.rb +29 -0
- data/lib/zucker/1/specification/unary_spec.rb +26 -0
- data/lib/zucker/1/specification/union_spec.rb +13 -0
- data/lib/zucker/1/square_brackets_for.rb +20 -0
- data/lib/zucker/1/string.rb +25 -0
- data/lib/zucker/1/unary.rb +22 -0
- data/lib/zucker/1/union.rb +14 -0
- data/lib/zucker/all.rb +2 -0
- data/lib/zucker/debug.rb +2 -0
- data/lib/zucker/default.rb +2 -0
- data/lib/zucker/edge/ideas/args.rb +22 -0
- data/lib/zucker/edge/ideas/args.yaml +19 -0
- data/lib/zucker/edge/ideas/args_spec.rb +19 -0
- data/lib/zucker/edge/ideas/clone_deep.rb +21 -0
- data/lib/zucker/edge/ideas/clone_deep_spec.rb +12 -0
- data/lib/zucker/edge/ideas/dclone.yaml +12 -0
- data/lib/zucker/edge/ideas/hash.rb +18 -0
- data/lib/zucker/edge/ideas/require_directory.rb +6 -0
- metadata +153 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jan Lelis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
PKG_FILES = FileList[ '[a-zA-Z]*', 'lib/**/*' ]
|
7
|
+
spec = Gem::Specification.new do |s|
|
8
|
+
s.name = 'zucker'
|
9
|
+
s.version = '0.9'
|
10
|
+
s.date = '2010-08-05'
|
11
|
+
s.authors = ['Jan Lelis']
|
12
|
+
s.email = 'mail@janlelis.de'
|
13
|
+
s.summary = 'Add more sugar to Ruby'
|
14
|
+
s.homepage = 'http://rubyzucker.info'
|
15
|
+
s.files = PKG_FILES.to_a
|
16
|
+
s.require_paths = [".","lib"]
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'build gem'
|
20
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
21
|
+
pkg.gem_spec = spec
|
22
|
+
end
|
23
|
+
|
data/lib/zucker.rb
ADDED
data/lib/zucker/1/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/1/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/1/#{rb}"}
|
25
|
+
|
@@ -0,0 +1,25 @@
|
|
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 object
|
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
|
+
authors:
|
24
|
+
- Jan Lelis
|
25
|
+
|
@@ -0,0 +1,18 @@
|
|
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
|
+
authors:
|
17
|
+
- Jan Lelis
|
18
|
+
|
@@ -0,0 +1,16 @@
|
|
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 an alias for ⇧inject(:+)⇧, but it is just 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
|
+
authors:
|
15
|
+
- Jan Lelis
|
16
|
+
|
@@ -0,0 +1,15 @@
|
|
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: '[1,2,3,4].map( &[:to_s, 2] ) # => ["1", "10", "11", "100"]'
|
6
|
+
info:
|
7
|
+
- Inspired by http://www.sanityinc.com/articles/adding-array-to-proc-to-ruby
|
8
|
+
- "More about to_proc: http://rbjl.net/29-become-a-proc-star"
|
9
|
+
package: default
|
10
|
+
versions:
|
11
|
+
- 1.9
|
12
|
+
- 1.8
|
13
|
+
authors:
|
14
|
+
- Jan Lelis
|
15
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
blank:
|
2
|
+
summary: Does pretty the same as in ActiveSupport (Every object can be asked if it is blank)
|
3
|
+
why: It's too familiar ;)
|
4
|
+
methods:
|
5
|
+
Object#blank?: "'an object'.blank? # => false"
|
6
|
+
package: default
|
7
|
+
info:
|
8
|
+
- See ActiveSupport
|
9
|
+
versions:
|
10
|
+
- 1.9
|
11
|
+
- 1.8
|
12
|
+
authors:
|
13
|
+
- Jan Lelis (this implementation)
|
14
|
+
|
@@ -0,0 +1,15 @@
|
|
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
|
+
authors:
|
13
|
+
- Facet authors
|
14
|
+
- Jan Lelis (this implementation)
|
15
|
+
|
@@ -0,0 +1,20 @@
|
|
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 http://rbjl.net/26-the-28-bytes-of-ruby-joy for more information and discussion
|
14
|
+
versions:
|
15
|
+
- 1.9
|
16
|
+
- 1.8
|
17
|
+
authors:
|
18
|
+
- Jan Lelis
|
19
|
+
- Yohan
|
20
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
enumerable:
|
2
|
+
summary: ⇧Enumerable⇧ extensions.
|
3
|
+
methods:
|
4
|
+
Enumerable#mash: "[1,2,3].mash{|e| [e, e.to_s] } # => {1=>'1',2=>'2',3=>'3'}"
|
5
|
+
package: default
|
6
|
+
info:
|
7
|
+
- Inspired by Ruby Facets' mash
|
8
|
+
versions:
|
9
|
+
- 1.9
|
10
|
+
- 1.8
|
11
|
+
authors:
|
12
|
+
- Jan Lelis
|
13
|
+
|
@@ -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#<<: "{1 => 2} << [3, 4] # => {1 => 2, 3 => 4}"
|
6
|
+
package: default
|
7
|
+
info:
|
8
|
+
- Some of the operators are inspired by Ruby Facets
|
9
|
+
versions:
|
10
|
+
- 1.9
|
11
|
+
- 1.8
|
12
|
+
authors:
|
13
|
+
- Jan Lelis
|
14
|
+
|
@@ -0,0 +1,13 @@
|
|
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
|
+
authors:
|
12
|
+
- Jan Lelis
|
13
|
+
|
@@ -0,0 +1,19 @@
|
|
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
|
+
authors:
|
18
|
+
- Jan Lelis
|
19
|
+
|