zucker 13.1 → 100.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +17 -2
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +22 -0
  5. data/Rakefile +17 -58
  6. data/doc/{zucker_doc.rb → create_documentation.rb} +67 -129
  7. data/doc/zucker.html +1774 -0
  8. data/lib/zucker.rb +12 -42
  9. data/lib/zucker/alias_for.rb +9 -16
  10. data/lib/zucker/all.rb +0 -2
  11. data/lib/zucker/array_op.rb +15 -0
  12. data/lib/zucker/blank.rb +39 -21
  13. data/lib/zucker/camel_snake.rb +15 -0
  14. data/lib/zucker/constantize.rb +29 -0
  15. data/lib/zucker/dir_extras.rb +20 -0
  16. data/lib/zucker/egonil.rb +13 -24
  17. data/lib/zucker/file_extras.rb +33 -0
  18. data/lib/zucker/hash_extras.rb +11 -0
  19. data/lib/zucker/hash_op.rb +28 -0
  20. data/lib/zucker/instance_variables_from.rb +34 -0
  21. data/lib/zucker/iterate.rb +24 -21
  22. data/lib/zucker/marshal_copy.rb +11 -0
  23. data/lib/zucker/mash.rb +22 -0
  24. data/lib/zucker/ords.rb +17 -0
  25. data/lib/zucker/regexp_union.rb +17 -0
  26. data/lib/zucker/square_brackets_for.rb +12 -15
  27. data/lib/zucker/string_extras.rb +15 -0
  28. data/lib/zucker/string_op.rb +20 -0
  29. data/lib/zucker/tap.rb +13 -8
  30. data/lib/zucker/unary_conversion.rb +25 -0
  31. data/spec/alias_for_spec.rb +11 -73
  32. data/spec/array_op_spec.rb +17 -0
  33. data/spec/blank_spec.rb +2 -0
  34. data/spec/camel_snake_spec.rb +15 -0
  35. data/spec/constantize_spec.rb +33 -0
  36. data/spec/dir_extras_spec.rb +32 -0
  37. data/spec/egonil_spec.rb +1 -0
  38. data/spec/file_extras_spec.rb +57 -0
  39. data/spec/hash_extras_spec.rb +11 -0
  40. data/spec/hash_op_spec.rb +28 -0
  41. data/spec/instance_variables_from_spec.rb +24 -0
  42. data/spec/iterate_spec.rb +2 -0
  43. data/spec/{mcopy_spec.rb → marshal_copy_spec.rb} +5 -3
  44. data/spec/mash_spec.rb +17 -0
  45. data/spec/ords_spec.rb +15 -0
  46. data/spec/{union_spec.rb → regexp_union_spec.rb} +4 -2
  47. data/spec/square_brackets_for_spec.rb +4 -12
  48. data/spec/string_extras_spec.rb +20 -0
  49. data/spec/string_op_spec.rb +22 -0
  50. data/spec/tap_spec.rb +2 -0
  51. data/spec/{unary_spec.rb → unary_conversion_spec.rb} +4 -2
  52. data/zucker.gemspec +8 -18
  53. metadata +75 -147
  54. data/.gemtest +0 -0
  55. data/README +0 -7
  56. data/desc/alias_for.yaml +0 -17
  57. data/desc/aliases.yaml +0 -18
  58. data/desc/array.yaml +0 -11
  59. data/desc/array_to_proc.yaml +0 -16
  60. data/desc/binding.yaml +0 -22
  61. data/desc/blank.yaml +0 -11
  62. data/desc/case.yaml +0 -9
  63. data/desc/cc.yaml +0 -10
  64. data/desc/class_to_proc.yaml +0 -11
  65. data/desc/dd.yaml +0 -23
  66. data/desc/egonil.yaml +0 -15
  67. data/desc/engine.yaml +0 -15
  68. data/desc/enumerable.yaml +0 -10
  69. data/desc/file.yaml +0 -14
  70. data/desc/hash.yaml +0 -14
  71. data/desc/hash_to_proc.yaml +0 -10
  72. data/desc/info.yaml +0 -20
  73. data/desc/iterate.yaml +0 -16
  74. data/desc/ivars.yaml +0 -19
  75. data/desc/kernel.yaml +0 -15
  76. data/desc/mcopy.yaml +0 -11
  77. data/desc/mm.yaml +0 -15
  78. data/desc/not.yaml +0 -11
  79. data/desc/oo.yaml +0 -10
  80. data/desc/os.yaml +0 -19
  81. data/desc/qq.yaml +0 -11
  82. data/desc/regexp_to_proc.yaml +0 -12
  83. data/desc/regexp_visualize.yaml +0 -23
  84. data/desc/ruby_version.yaml +0 -28
  85. data/desc/sandbox.yaml +0 -13
  86. data/desc/square_brackets_for.yaml +0 -22
  87. data/desc/string.yaml +0 -22
  88. data/desc/tap.yaml +0 -17
  89. data/desc/unary.yaml +0 -15
  90. data/desc/union.yaml +0 -10
  91. data/doc/zucker_doc.html +0 -3042
  92. data/lib/zucker/aliases.rb +0 -52
  93. data/lib/zucker/array.rb +0 -15
  94. data/lib/zucker/array_to_proc.rb +0 -19
  95. data/lib/zucker/binding.rb +0 -35
  96. data/lib/zucker/case.rb +0 -14
  97. data/lib/zucker/cc.rb +0 -31
  98. data/lib/zucker/class_to_proc.rb +0 -13
  99. data/lib/zucker/control.rb +0 -4
  100. data/lib/zucker/dd.rb +0 -24
  101. data/lib/zucker/debug.rb +0 -4
  102. data/lib/zucker/default.rb +0 -4
  103. data/lib/zucker/engine.rb +0 -70
  104. data/lib/zucker/enumerable.rb +0 -15
  105. data/lib/zucker/env.rb +0 -4
  106. data/lib/zucker/extensions.rb +0 -4
  107. data/lib/zucker/file.rb +0 -28
  108. data/lib/zucker/hash.rb +0 -28
  109. data/lib/zucker/hash_to_proc.rb +0 -17
  110. data/lib/zucker/info.rb +0 -193
  111. data/lib/zucker/ivars.rb +0 -29
  112. data/lib/zucker/kernel.rb +0 -42
  113. data/lib/zucker/mcopy.rb +0 -11
  114. data/lib/zucker/mm.rb +0 -41
  115. data/lib/zucker/not.rb +0 -20
  116. data/lib/zucker/object.rb +0 -4
  117. data/lib/zucker/oo.rb +0 -18
  118. data/lib/zucker/os.rb +0 -55
  119. data/lib/zucker/qq.rb +0 -13
  120. data/lib/zucker/regexp_to_proc.rb +0 -13
  121. data/lib/zucker/regexp_visualize.rb +0 -31
  122. data/lib/zucker/ruby_version.rb +0 -120
  123. data/lib/zucker/sandbox.rb +0 -17
  124. data/lib/zucker/shortcuts.rb +0 -4
  125. data/lib/zucker/string.rb +0 -55
  126. data/lib/zucker/to_proc.rb +0 -4
  127. data/lib/zucker/unary.rb +0 -25
  128. data/lib/zucker/union.rb +0 -17
  129. data/spec/aliases_spec.rb +0 -13
  130. data/spec/array_spec.rb +0 -16
  131. data/spec/array_to_proc_spec.rb +0 -12
  132. data/spec/binding_spec.rb +0 -6
  133. data/spec/case_spec.rb +0 -15
  134. data/spec/cc_spec.rb +0 -6
  135. data/spec/class_to_proc_spec.rb +0 -9
  136. data/spec/dd_spec.rb +0 -37
  137. data/spec/engine_spec.rb +0 -11
  138. data/spec/enumerable_spec.rb +0 -8
  139. data/spec/file_spec.rb +0 -46
  140. data/spec/hash_spec.rb +0 -25
  141. data/spec/hash_to_proc_spec.rb +0 -12
  142. data/spec/info_spec.rb +0 -8
  143. data/spec/ivars_spec.rb +0 -20
  144. data/spec/kernel_spec.rb +0 -42
  145. data/spec/mm_spec.rb +0 -6
  146. data/spec/not_spec.rb +0 -10
  147. data/spec/oo_spec.rb +0 -6
  148. data/spec/os_spec.rb +0 -37
  149. data/spec/qq_spec.rb +0 -19
  150. data/spec/regexp_to_proc_spec.rb +0 -9
  151. data/spec/regexp_visualize_spec.rb +0 -38
  152. data/spec/ruby_version_spec.rb +0 -55
  153. data/spec/sandbox_spec.rb +0 -14
  154. data/spec/string_spec.rb +0 -65
data/lib/zucker/ivars.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'zucker'
2
- module Zucker Ivars = true end
3
-
4
- def instance_variables_from(obj, *only)
5
- iter =
6
- if obj.is_a? Binding
7
- obj.eval('local_variables').map{|e| [obj.eval("#{e}"), e] }
8
- elsif obj.is_a? Hash
9
- obj.map{|k,v| [v,k] }
10
- else
11
- # elsif obj.is_a? Enumerable
12
- obj.each.with_index
13
- end
14
-
15
- ret = []
16
- iter.each{ |value, arg|
17
- arg = arg.to_s
18
- if only.include?(arg) || only.include?(arg.to_sym) || only.empty?
19
- arg = '_' + arg if (48..57).member? arg.unpack('C')[0] # 1.8+1.9
20
- ret << ivar = :"@#{arg}"
21
- self.instance_variable_set ivar, value
22
- end
23
- }
24
- ret
25
- end
26
- alias ivars instance_variables_from
27
-
28
- # J-_-L
29
-
data/lib/zucker/kernel.rb DELETED
@@ -1,42 +0,0 @@
1
- require 'zucker'
2
- module Zucker Kernel = true end
3
-
4
- module Kernel
5
- private
6
-
7
- def activate_warnings!
8
- $VERBOSE = true
9
- end
10
-
11
- def deactivate_warnings!
12
- $VERBOSE = false
13
- end
14
-
15
- def library?
16
- caller[0].rindex(/:\d+(:in `.*')?$/)
17
- $PROGRAM_NAME != $` # __FILE__
18
- end
19
-
20
- def executed_directly?
21
- caller[0].rindex(/:\d+(:in `.*')?$/)
22
- $PROGRAM_NAME == $` # __FILE__
23
- end
24
- alias standalone? executed_directly?
25
- alias directly_executed? executed_directly?
26
-
27
- def irb?
28
- (defined?(IRB) && $0 =~ /irb/) || (defined?(Ripl) && $0 =~ /ripl/)
29
- end
30
-
31
- def ignore_sigint! # ctrl+c
32
- Signal.trap(*%w|SIGINT IGNORE|)
33
- true
34
- end
35
-
36
- def ignore_sigquit! # ctrl+\
37
- Signal.trap(*%w|SIGQUIT IGNORE|)
38
- true
39
- end
40
- end
41
-
42
- # J-_-L
data/lib/zucker/mcopy.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'zucker'
2
- module Zucker Mcopy = true end
3
-
4
- class Object
5
- def mcopy
6
- Marshal.load Marshal.dump self
7
- end
8
- end
9
-
10
- # J-_-L
11
-
data/lib/zucker/mm.rb DELETED
@@ -1,41 +0,0 @@
1
- require 'zucker'
2
- module Zucker Mm = true end
3
-
4
- module Kernel
5
- def m(levels = 1)
6
- # output helper
7
- mputs = proc{ |e| puts e.map(&:to_s)*' ' }
8
-
9
- # how to get results
10
- if self.is_a? Module
11
- klass, method_function = self, :public_methods
12
- else
13
- klass, method_function = self.class, :public_instance_methods
14
- end
15
-
16
- # eigenclass
17
- eigen = self.singleton_methods
18
- if !eigen.empty?
19
- puts '= Eigenclass' # sorry for not being up to date, I just love the word
20
- mputs[ self.singleton_methods ]
21
- end
22
-
23
- # display
24
- levels.times{ |level|
25
- if cur = klass.ancestors[level]
26
- puts "= #{cur}" # put class name
27
- mputs[ cur.send method_function, false ] # put methods of the class
28
- else
29
- break
30
- end
31
- }
32
-
33
- nil
34
- end
35
-
36
- alias mm m
37
- alias method_list m
38
- end
39
-
40
- # J-_-L
41
-
data/lib/zucker/not.rb DELETED
@@ -1,20 +0,0 @@
1
- require 'zucker'
2
- module Zucker Not = true end
3
-
4
- class Object
5
- def not
6
- NotClass.new self
7
- end
8
-
9
- class NotClass < BasicObject
10
- def initialize(receiver)
11
- @receiver = receiver
12
- end
13
-
14
- def method_missing(m, *args, &block)
15
- not @receiver.public_send( m, *args, &block )
16
- end
17
- end
18
- end
19
-
20
- # J-_-L
data/lib/zucker/object.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'zucker'
2
- Zucker.require_this __FILE__
3
-
4
- # J-_-L
data/lib/zucker/oo.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'zucker'
2
- module Zucker Oo = true end
3
-
4
- module Kernel
5
- private
6
-
7
- def o(desc = nil)
8
- caller[0].rindex( /:(\d+)(:in (`.*'))?$/ )
9
- m = $3 ? "method #$3, " : ""
10
- d = desc ? "#{desc}: r" : 'R'
11
-
12
- puts "#{d}eached #{m}line #$1 of file #$`"
13
- # [$`, $1.to_i, $3.to_sym, desc]
14
- end
15
- alias oo o
16
- end
17
-
18
- # J-_-L
data/lib/zucker/os.rb DELETED
@@ -1,55 +0,0 @@
1
- require 'zucker'
2
- require 'rbconfig'
3
- module Zucker Os = true end
4
-
5
- module OS
6
- class << self
7
- def is?(what)
8
- what === RbConfig::CONFIG['host_os']
9
- end
10
- alias is is?
11
-
12
- def to_s
13
- RbConfig::CONFIG['host_os']
14
- end
15
- end
16
-
17
- module_function
18
-
19
- def linux?
20
- OS.is?( /linux|cygwin/ )
21
- end
22
-
23
- def mac?
24
- OS.is?( /mac|darwin/ )
25
- end
26
-
27
- def bsd?
28
- OS.is?( /bsd/ )
29
- end
30
-
31
- def windows?
32
- OS.is?( /mswin|mingw/ )
33
- end
34
-
35
- def solaris?
36
- OS.is?( /solaris|sunos/ )
37
- end
38
-
39
- def posix?
40
- linux? or mac? or bsd? or solaris? or begin
41
- fork do end
42
- true
43
- rescue NotImplementedError, NoMethodError
44
- false
45
- end
46
- end
47
-
48
- #def symbian?
49
- #TODO who knows what symbian returns?
50
- #end
51
-
52
- # ...
53
- end
54
-
55
- # J-_-L
data/lib/zucker/qq.rb DELETED
@@ -1,13 +0,0 @@
1
- require 'zucker'
2
- module Zucker Qq = true end
3
-
4
- module Kernel
5
- private
6
-
7
- def q(*args)
8
- puts args.map( &:inspect )*' ' unless args.empty?
9
- end
10
- alias qq q
11
- end
12
-
13
- # J-_-L
@@ -1,13 +0,0 @@
1
- require 'zucker'
2
- module Zucker RegexpToProc = true end
3
-
4
- class Regexp
5
- def to_proc
6
- proc do |e|
7
- e.to_s[self]
8
- end
9
- end
10
- end
11
-
12
- # J-_-L
13
-
@@ -1,31 +0,0 @@
1
- require 'zucker'
2
- module Zucker RegexpVisualize = true end
3
-
4
- class Regexp
5
- def visualize(string, groups = nil)
6
- if self =~ string
7
- if !groups
8
- puts $` + ' >' + $& + '< ' + $'
9
- else
10
- Array( groups ).each{ |group|
11
- begin
12
- gr_string = string.dup
13
- gr_string[ $~.end( group ), 0 ] = '< '
14
- gr_string[ $~.begin( group ), 0 ] = ' >'
15
- puts group.to_s + ': ' + gr_string
16
- rescue IndexError, defined?(Rubinius) && Rubinius::ObjectBoundsExceededError
17
- puts group.to_s + ': no match'
18
- end
19
- }
20
- end
21
- else
22
- puts 'no match'
23
- end
24
-
25
- nil
26
- end
27
-
28
- alias vis visualize
29
- end
30
-
31
- # J-_-L
@@ -1,120 +0,0 @@
1
- require 'zucker'
2
- require 'date'
3
- require 'time'
4
- module Zucker RubyVersion = true end
5
-
6
- module RubyVersion
7
- class << self
8
- def to_s
9
- RUBY_VERSION
10
- end
11
- alias inspect to_s
12
-
13
- # comparable
14
- def <=>(other)
15
- value = case other
16
- when Integer
17
- RUBY_VERSION.to_i
18
- when Float
19
- RUBY_VERSION.to_f
20
- when String
21
- RUBY_VERSION
22
- when Date, Time
23
- other.class.parse(RUBY_RELEASE_DATE)
24
- else
25
- other = other.to_s
26
- RUBY_VERSION
27
- end
28
- value <=> other
29
- end
30
- include Comparable
31
-
32
- # chaining for dsl-like language
33
- def is?(other = nil)
34
- if other
35
- RubyVersion == other
36
- else
37
- RubyVersion
38
- end
39
- end
40
- alias is is?
41
-
42
- # aliases
43
- alias below <
44
- alias below? <
45
- alias at_most <=
46
- alias at_most? <=
47
- alias above >
48
- alias above? >
49
- alias at_least >=
50
- alias at_least? >=
51
- alias exactly ==
52
- alias exactly? ==
53
- def not(other)
54
- self != other
55
- end
56
- alias not? not
57
- alias between between?
58
-
59
- # compare dates
60
- def newer_than(other)
61
- if other.is_a? Date or other.is_a? Time
62
- RubyVersion > other
63
- else
64
- RUBY_RELEASE_DATE > other.to_s
65
- end
66
- end
67
- alias newer_than? newer_than
68
-
69
- def older_than(other)
70
- if other.is_a? Date or other.is_a? Time
71
- RubyVersion < other
72
- else
73
- RUBY_RELEASE_DATE < other.to_s
74
- end
75
- end
76
- alias older_than? older_than
77
-
78
- def released_today
79
- RubyVersion.date == Date.today
80
- end
81
- alias released_today? released_today
82
-
83
- # accessors
84
-
85
- def major
86
- RUBY_VERSION.to_i
87
- end
88
- alias main major
89
-
90
- def minor
91
- RUBY_VERSION.split('.')[1].to_i
92
- end
93
- alias mini minor
94
-
95
- def tiny
96
- RUBY_VERSION.split('.')[2].to_i
97
- end
98
-
99
- alias teeny tiny
100
-
101
- def patchlevel
102
- RUBY_PATCHLEVEL
103
- end
104
-
105
- def platform
106
- RUBY_PLATFORM
107
- end
108
-
109
- def release_date
110
- Date.parse RUBY_RELEASE_DATE
111
- end
112
- alias date release_date
113
-
114
- def description
115
- RUBY_DESCRIPTION
116
- end
117
- end
118
- end
119
-
120
- # J-_-L
@@ -1,17 +0,0 @@
1
- require 'zucker'
2
- module Zucker Sandbox = true end
3
-
4
- module Kernel
5
- private
6
-
7
- def sandbox
8
- warn "zucker: sandbox does not work in rbx and jruby" if defined?(RUBY_ENGINE) && ( RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx' )
9
- Thread.start do
10
- $SAFE = 4
11
- yield
12
- end.value
13
- end
14
- end
15
-
16
- # J-_-L
17
-
@@ -1,4 +0,0 @@
1
- require 'zucker'
2
- Zucker.require_this __FILE__
3
-
4
- # J-_-L
data/lib/zucker/string.rb DELETED
@@ -1,55 +0,0 @@
1
- require 'zucker'
2
- module Zucker String = true end
3
-
4
- class String
5
- def -(rem)
6
- gsub( Regexp === rem ? rem : rem.to_s, '' )
7
- end
8
-
9
- def ^(pos)
10
- pos = pos.to_i
11
- if pos >= 0
12
- self[pos..-1]
13
- else
14
- self[0...pos]
15
- end
16
- end
17
-
18
- def lchomp(arg = $/)
19
- reverse.chomp(arg).reverse
20
- end
21
-
22
- def lchomp!(arg = $/)
23
- reverse.chomp!(arg).reverse
24
- end
25
-
26
- def ords
27
- unpack 'C*'
28
- # bytes.to_a
29
- end
30
-
31
- def constantize(default_value = nil) # always uses global scope as in AS... is this good?
32
- get_constant = lambda{
33
- self.split(/::/).inject( Object ){ |base_constant, current_constant|
34
- base_constant.const_get current_constant
35
- }
36
- }
37
-
38
- if !default_value && !block_given?
39
- get_constant.call
40
- else
41
- begin
42
- get_constant.call
43
- rescue NameError
44
- if block_given?
45
- yield self
46
- else
47
- default_value
48
- end
49
- end
50
- end
51
- end
52
- end
53
-
54
- # J-_-L
55
-