zucker 0.9 → 1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/zucker.rb +6 -1
- data/lib/zucker/1/{descriptions → desc}/D.yaml +2 -4
- data/lib/zucker/1/{descriptions → desc}/aliases.yaml +0 -2
- data/lib/zucker/1/{descriptions → desc}/array.yaml +1 -3
- data/lib/zucker/1/{descriptions → desc}/array2proc.yaml +2 -4
- data/lib/zucker/1/{descriptions → desc}/binding.yaml +0 -2
- data/lib/zucker/1/{descriptions → desc}/blank.yaml +0 -2
- data/lib/zucker/1/{descriptions → desc}/class2proc.yaml +2 -5
- data/lib/zucker/1/{descriptions → desc}/egonil.yaml +2 -5
- data/lib/zucker/1/{descriptions → desc}/enumerable.yaml +0 -2
- data/lib/zucker/1/{descriptions → desc}/hash.yaml +0 -2
- data/lib/zucker/1/{descriptions → desc}/hash2proc.yaml +1 -3
- data/lib/zucker/1/{descriptions → desc}/iterate.yaml +1 -3
- data/lib/zucker/1/{descriptions → desc}/ivars.yaml +1 -3
- data/lib/zucker/1/{descriptions → desc}/kernel.yaml +0 -0
- data/lib/zucker/1/{descriptions → desc}/mcopy.yaml +0 -2
- data/lib/zucker/1/{descriptions → desc}/mm.yaml +1 -3
- data/lib/zucker/1/{descriptions → desc}/regexp2proc.yaml +1 -3
- data/lib/zucker/1/{descriptions → desc}/sandbox.yaml +0 -2
- data/lib/zucker/1/{descriptions → desc}/square_brackets_for.yaml +0 -2
- data/lib/zucker/1/{descriptions → desc}/string.yaml +0 -2
- data/lib/zucker/1/desc/unary.yaml +15 -0
- data/lib/zucker/1/{descriptions → desc}/union.yaml +0 -0
- data/lib/zucker/1/{documentation → doc}/meta.yaml +0 -0
- data/lib/zucker/1/{documentation → doc}/zucker_doc.html +732 -604
- data/lib/zucker/1/doc/zucker_doc.rb +493 -0
- data/lib/zucker/1/hash2proc.rb +2 -0
- data/lib/zucker/1/{specification → spec}/D_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/aliases_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/array2proc_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/array_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/binding_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/blank_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/class2proc_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/egonil_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/enumerable_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/hash2proc_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/hash_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/iterate_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/ivars_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/kernel_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/mcopy_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/mm_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/regexp2proc_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/sandbox_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/square_brackets_for_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/string_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/unary_spec.rb +0 -0
- data/lib/zucker/1/{specification → spec}/union_spec.rb +0 -0
- data/lib/zucker/D.rb +19 -0
- data/lib/zucker/aliases.rb +28 -0
- data/lib/zucker/all.rb +5 -1
- data/lib/zucker/array.rb +17 -0
- data/lib/zucker/array2proc.rb +10 -0
- data/lib/zucker/binding.rb +25 -0
- data/lib/zucker/blank.rb +26 -0
- data/lib/zucker/class2proc.rb +10 -0
- data/lib/zucker/debug.rb +3 -1
- data/lib/zucker/default.rb +24 -1
- data/lib/zucker/desc/D.yaml +23 -0
- data/lib/zucker/desc/aliases.yaml +16 -0
- data/lib/zucker/desc/array.yaml +14 -0
- data/lib/zucker/desc/array2proc.yaml +13 -0
- data/lib/zucker/desc/binding.yaml +10 -0
- data/lib/zucker/desc/blank.yaml +12 -0
- data/lib/zucker/desc/class2proc.yaml +12 -0
- data/lib/zucker/desc/egonil.yaml +17 -0
- data/lib/zucker/desc/enumerable.yaml +11 -0
- data/lib/zucker/desc/hash.yaml +12 -0
- data/lib/zucker/desc/hash2proc.yaml +11 -0
- data/lib/zucker/desc/iterate.yaml +17 -0
- data/lib/zucker/desc/ivars.yaml +20 -0
- data/lib/zucker/desc/kernel.yaml +13 -0
- data/lib/zucker/desc/mcopy.yaml +12 -0
- data/lib/zucker/desc/mm.yaml +12 -0
- data/lib/zucker/desc/regexp2proc.yaml +13 -0
- data/lib/zucker/desc/sandbox.yaml +14 -0
- data/lib/zucker/desc/square_brackets_for.yaml +23 -0
- data/lib/zucker/desc/string.yaml +13 -0
- data/lib/zucker/desc/unary.yaml +15 -0
- data/lib/zucker/desc/union.yaml +11 -0
- data/lib/zucker/doc/meta.yaml +4 -0
- data/lib/zucker/doc/zucker_doc.html +1286 -0
- data/lib/zucker/doc/zucker_doc.rb +493 -0
- data/lib/zucker/egonil.rb +14 -0
- data/lib/zucker/enumerable.rb +12 -0
- data/lib/zucker/hash.rb +19 -0
- data/lib/zucker/hash2proc.rb +14 -0
- data/lib/zucker/iterate.rb +23 -0
- data/lib/zucker/ivars.rb +26 -0
- data/lib/zucker/kernel.rb +20 -0
- data/lib/zucker/mcopy.rb +9 -0
- data/lib/zucker/mm.rb +31 -0
- data/lib/zucker/regexp2proc.rb +10 -0
- data/lib/zucker/sandbox.rb +15 -0
- data/lib/zucker/spec/D_spec.rb +27 -0
- data/lib/zucker/spec/aliases_spec.rb +34 -0
- data/lib/zucker/spec/array2proc_spec.rb +8 -0
- data/lib/zucker/spec/array_spec.rb +23 -0
- data/lib/zucker/spec/binding_spec.rb +6 -0
- data/lib/zucker/spec/blank_spec.rb +20 -0
- data/lib/zucker/spec/class2proc_spec.rb +9 -0
- data/lib/zucker/spec/egonil_spec.rb +30 -0
- data/lib/zucker/spec/enumerable_spec.rb +8 -0
- data/lib/zucker/spec/hash2proc_spec.rb +12 -0
- data/lib/zucker/spec/hash_spec.rb +10 -0
- data/lib/zucker/spec/iterate_spec.rb +54 -0
- data/lib/zucker/spec/ivars_spec.rb +20 -0
- data/lib/zucker/spec/kernel_spec.rb +34 -0
- data/lib/zucker/spec/mcopy_spec.rb +13 -0
- data/lib/zucker/spec/mm_spec.rb +6 -0
- data/lib/zucker/spec/regexp2proc_spec.rb +9 -0
- data/lib/zucker/spec/sandbox_spec.rb +7 -0
- data/lib/zucker/spec/square_brackets_for_spec.rb +59 -0
- data/lib/zucker/spec/string_spec.rb +29 -0
- data/lib/zucker/spec/unary_spec.rb +26 -0
- data/lib/zucker/spec/union_spec.rb +13 -0
- data/lib/zucker/square_brackets_for.rb +20 -0
- data/lib/zucker/string.rb +25 -0
- data/lib/zucker/unary.rb +22 -0
- data/lib/zucker/union.rb +14 -0
- metadata +119 -51
- data/lib/zucker/1/descriptions/unary.yaml +0 -15
- data/lib/zucker/1/documentation/zucker_doc.rb +0 -369
data/lib/zucker/1/hash2proc.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/zucker/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/all.rb
CHANGED
data/lib/zucker/array.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
|
+
|
data/lib/zucker/blank.rb
ADDED
@@ -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
|
+
|
data/lib/zucker/debug.rb
CHANGED
data/lib/zucker/default.rb
CHANGED
@@ -1,2 +1,25 @@
|
|
1
|
-
|
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}"}
|
2
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 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
|
+
|
@@ -0,0 +1,13 @@
|
|
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 →this article→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
|
+
|
@@ -0,0 +1,12 @@
|
|
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
|
+
|
@@ -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,12 @@
|
|
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
|
+
|
@@ -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,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
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
ivars:
|
2
|
+
summary: This method lets you easily assign lots of instance variables.
|
3
|
+
why: |
|
4
|
+
Often, you have to write boilerplate code for assigning instance varialbles, for example this one:
|
5
|
+
⇧def initialize(variable1, variable2)
|
6
|
+
@variable1, @variable2 = variable1, variable2
|
7
|
+
end⇧
|
8
|
+
methods:
|
9
|
+
instance_variables_from, ivars: |
|
10
|
+
def a_method(a = 1, b = 2)
|
11
|
+
instance_variables_from binding # assigns @a and @b
|
12
|
+
|
13
|
+
params = {:c => 3, :d => 4}
|
14
|
+
instance_variables_from params # # assigns @c and @d
|
15
|
+
end
|
16
|
+
package: default
|
17
|
+
versions:
|
18
|
+
- 1.9
|
19
|
+
- 1.8
|
20
|
+
|