zucker 10 → 11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG +10 -0
  2. data/Rakefile +2 -2
  3. data/desc/binding.yaml +2 -2
  4. data/desc/kernel.yaml +2 -1
  5. data/desc/string.yaml +2 -2
  6. data/doc/zucker_doc.html +107 -42
  7. data/lib/zucker.rb +5 -5
  8. data/lib/zucker/alias_for.rb +1 -0
  9. data/lib/zucker/aliases.rb +1 -0
  10. data/lib/zucker/array.rb +1 -0
  11. data/lib/zucker/array_to_proc.rb +2 -1
  12. data/lib/zucker/binding.rb +18 -15
  13. data/lib/zucker/blank.rb +1 -0
  14. data/lib/zucker/cc.rb +1 -0
  15. data/lib/zucker/class_to_proc.rb +2 -1
  16. data/lib/zucker/dd.rb +1 -0
  17. data/lib/zucker/egonil.rb +1 -0
  18. data/lib/zucker/engine.rb +1 -0
  19. data/lib/zucker/enumerable.rb +2 -1
  20. data/lib/zucker/file.rb +6 -0
  21. data/lib/zucker/hash.rb +1 -0
  22. data/lib/zucker/hash_to_proc.rb +1 -0
  23. data/lib/zucker/info.rb +1 -0
  24. data/lib/zucker/iterate.rb +3 -2
  25. data/lib/zucker/ivars.rb +1 -0
  26. data/lib/zucker/kernel.rb +7 -1
  27. data/lib/zucker/mcopy.rb +1 -0
  28. data/lib/zucker/mm.rb +1 -0
  29. data/lib/zucker/not.rb +1 -0
  30. data/lib/zucker/oo.rb +1 -0
  31. data/lib/zucker/os.rb +1 -0
  32. data/lib/zucker/qq.rb +1 -0
  33. data/lib/zucker/regexp_to_proc.rb +1 -0
  34. data/lib/zucker/regexp_visualize.rb +6 -1
  35. data/lib/zucker/sandbox.rb +2 -0
  36. data/lib/zucker/square_brackets_for.rb +1 -0
  37. data/lib/zucker/string.rb +1 -0
  38. data/lib/zucker/tap.rb +3 -2
  39. data/lib/zucker/unary.rb +1 -0
  40. data/lib/zucker/union.rb +1 -0
  41. data/lib/zucker/version.rb +1 -0
  42. data/spec/kernel_spec.rb +6 -1
  43. data/spec/regexp_visualize_spec.rb +1 -1
  44. data/spec/sandbox_spec.rb +1 -1
  45. data/spec/version_spec.rb +2 -2
  46. data/zucker.gemspec +12 -3
  47. metadata +6 -6
data/lib/zucker.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Zucker
4
4
  # version and date get modified by the :prepare_release rake task
5
- VERSION = '10'
6
- DATE = '2011-04-29'
5
+ VERSION = '11'
6
+ DATE = '2011-05-25'
7
7
 
8
8
  # cube list
9
9
  PACKAGES = {
@@ -22,7 +22,7 @@ module Zucker
22
22
  # Zucker require helpers
23
23
  def require_cube(cube, version = '')
24
24
  unless RUBY_VERSION < '1.9' && Zucker::NON_1_8_CUBES.include?(cube)
25
- require File.expand_path( File.join('..', 'zucker', version, cube), __FILE__)
25
+ require ::File.expand_path( ::File.join('..', 'zucker', version, cube), __FILE__)
26
26
  end
27
27
  end
28
28
 
@@ -33,9 +33,9 @@ module Zucker
33
33
  end
34
34
 
35
35
  def require_this(filename)
36
- version= File.split( File.expand_path( filename) )[-2]
36
+ version= ::File.split( ::File.expand_path( filename) )[-2]
37
37
  version = '' if version !~ /^\d+$/
38
- package = File.basename( filename ).chomp( File.extname( filename ))
38
+ package = ::File.basename( filename ).chomp( ::File.extname( filename ))
39
39
  Zucker.require_package(package, version)
40
40
  end
41
41
 
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker AliasFor = true end
2
3
 
3
4
  def alias_for(m, *aliases)
4
5
  aliases.each{ |a|
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Aliases = true end
2
3
 
3
4
  class Object
4
5
  alias is_an? is_a? # thanks to utility_belt
data/lib/zucker/array.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Array = true end
2
3
 
3
4
  class Array
4
5
  def ^(other) # TODO: more efficient
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker ArrayToProc = true end
2
3
 
3
4
  class Array
4
5
  def to_proc
@@ -8,7 +9,7 @@ class Array
8
9
  nested_array.to_proc.call result
9
10
  }
10
11
  else
11
- obj.send *self
12
+ obj.send(*self)
12
13
  end
13
14
  }
14
15
  end
@@ -1,19 +1,21 @@
1
1
  require 'zucker'
2
+ module Zucker Binding = true end
2
3
 
3
- class Binding
4
- def variables
5
- put_vars = lambda { |array|
6
- if array.empty?
7
- ' - none'
8
- else
9
- array.map{|e|
10
- val = (self.eval "#{e}").inspect
11
- " - #{e}: #{ val }"
12
- }.join "\n"
13
- end
14
- }
4
+ unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
5
+ class Binding
6
+ def variables
7
+ put_vars = lambda { |array|
8
+ if array.empty?
9
+ ' - none'
10
+ else
11
+ array.map{|e|
12
+ val = (self.eval "#{e}").inspect
13
+ " - #{e}: #{ val }"
14
+ }.join "\n"
15
+ end
16
+ }
15
17
 
16
- puts "#{self.to_s}
18
+ puts "#{self.to_s}
17
19
  local variables
18
20
  #{ put_vars[ self.eval 'local_variables' ] }
19
21
  (instance variables)
@@ -23,9 +25,10 @@ self
23
25
  block_given?
24
26
  - #{self.eval 'block_given?'}"
25
27
 
26
- end
28
+ end
27
29
 
28
- alias vars variables
30
+ alias vars variables
31
+ end
29
32
  end
30
33
 
31
34
  # J-_-L
data/lib/zucker/blank.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Blank = true end
2
3
 
3
4
  class Object
4
5
  def blank?
data/lib/zucker/cc.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Cc = true end
2
3
 
3
4
  module Kernel
4
5
  private
@@ -1,9 +1,10 @@
1
1
  require 'zucker'
2
+ module Zucker ClassToProc = true end
2
3
 
3
4
  class Class
4
5
  def to_proc
5
6
  Proc.new do |*args|
6
- self.new *args
7
+ self.new(*args)
7
8
  end
8
9
  end
9
10
  end
data/lib/zucker/dd.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Dd = true end
2
3
 
3
4
  module Kernel
4
5
  def d(*args, &block)
data/lib/zucker/egonil.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Egonil = true end
2
3
 
3
4
  # code by Yohan, slightly edited and comments by me
4
5
  def egonil(&block)
data/lib/zucker/engine.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Engine = true end
2
3
 
3
4
  module RubyEngine
4
5
  # try to guess the interpreter
@@ -1,10 +1,11 @@
1
1
  require 'zucker'
2
+ module Zucker Enumerable = true end
2
3
 
3
4
  module Enumerable
4
5
  def mash
5
6
  ret = {}
6
7
  each{ |kv|
7
- ret.store *( yield(kv)[0,2] )
8
+ ret.store( *(yield(kv)[0,2]) )
8
9
  }
9
10
  ret
10
11
  end
data/lib/zucker/file.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'zucker'
2
+ module Zucker File = true end
3
+
1
4
  class << File
2
5
  def gsub(filename, regex_hash)
3
6
  data = File.read filename
@@ -20,3 +23,6 @@ class << File
20
23
  File.delete filename
21
24
  end
22
25
  end
26
+
27
+ # J-_-L
28
+
data/lib/zucker/hash.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Hash = true end
2
3
 
3
4
  class Hash
4
5
  def self.zip(keys,values)
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker HashToProc = true end
2
3
 
3
4
  class Hash
4
5
  def to_proc
data/lib/zucker/info.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'zucker'
2
2
  require 'rbconfig'
3
3
  require 'etc'
4
+ module Zucker Info = true end
4
5
 
5
6
  module Info
6
7
  class << self
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Iterate = true end
2
3
 
3
4
  def iterate(*params)
4
5
  # params.shift.zip(*params).each{ |*elements| yield *elements }
@@ -14,9 +15,9 @@ def iterate(*params)
14
15
  else # multiple params
15
16
  max_size = [first, *params].max_by(&:count).size
16
17
  padded_first = first.to_a + [nil]*(max_size - first.count) # append nils
17
- obj = padded_first.zip *params
18
+ obj = padded_first.zip(*params)
18
19
  if block_given?
19
- obj.map{|es| yield *es }
20
+ obj.map{|es| yield(*es) }
20
21
  else
21
22
  obj.map.to_enum
22
23
  end
data/lib/zucker/ivars.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Ivars = true end
2
3
 
3
4
  def instance_variables_from(obj, *only)
4
5
  iter =
data/lib/zucker/kernel.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Kernel = true end
2
3
 
3
4
  module Kernel
4
5
  private
@@ -28,7 +29,12 @@ module Kernel
28
29
  end
29
30
 
30
31
  def ignore_sigint! # ctrl+c
31
- Signal.trap *%w|SIGINT IGNORE|
32
+ Signal.trap(*%w|SIGINT IGNORE|)
33
+ true
34
+ end
35
+
36
+ def ignore_sigquit! # ctrl+\
37
+ Signal.trap(*%w|SIGQUIT IGNORE|)
32
38
  true
33
39
  end
34
40
  end
data/lib/zucker/mcopy.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Mcopy = true end
2
3
 
3
4
  class Object
4
5
  def mcopy
data/lib/zucker/mm.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Mm = true end
2
3
 
3
4
  module Kernel
4
5
  def m(levels = 1)
data/lib/zucker/not.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Not = true end
2
3
 
3
4
  class Object
4
5
  def not
data/lib/zucker/oo.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Oo = true end
2
3
 
3
4
  module Kernel
4
5
  private
data/lib/zucker/os.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'zucker'
2
2
  require 'rbconfig'
3
+ module Zucker Os = true end
3
4
 
4
5
  module OS
5
6
  class << self
data/lib/zucker/qq.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Qq = true end
2
3
 
3
4
  module Kernel
4
5
  private
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker RegexpToProc = true end
2
3
 
3
4
  class Regexp
4
5
  def to_proc
@@ -1,3 +1,6 @@
1
+ require 'zucker'
2
+ module Zucker RegexpVisualize = true end
3
+
1
4
  class Regexp
2
5
  def visualize(string, groups = nil)
3
6
  if self =~ string
@@ -10,7 +13,7 @@ class Regexp
10
13
  gr_string[ $~.end( group ), 0 ] = '< '
11
14
  gr_string[ $~.begin( group ), 0 ] = ' >'
12
15
  puts group.to_s + ': ' + gr_string
13
- rescue IndexError
16
+ rescue IndexError, defined?(Rubinius) && Rubinius::ObjectBoundsExceededError
14
17
  puts group.to_s + ': no match'
15
18
  end
16
19
  }
@@ -24,3 +27,5 @@ class Regexp
24
27
 
25
28
  alias vis visualize
26
29
  end
30
+
31
+ # J-_-L
@@ -1,9 +1,11 @@
1
1
  require 'zucker'
2
+ module Zucker Sandbox = true end
2
3
 
3
4
  module Kernel
4
5
  private
5
6
 
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' )
7
9
  Thread.start do
8
10
  $SAFE = 4
9
11
  yield
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker SquareBracketsFor = true end
2
3
 
3
4
  class Module
4
5
  def square_brackets_for(ivar, assignment = true)
data/lib/zucker/string.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker String = true end
2
3
 
3
4
  class String
4
5
  def -(rem)
data/lib/zucker/tap.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require 'zucker'
2
+ module Zucker Tap = true end
2
3
 
3
4
  def tap_on(obj, &block)
4
- obj.tap &block
5
+ obj.tap(&block)
5
6
  end
6
7
 
7
8
  def make_new(what, *args, &block)
8
- what.new(*args).tap &block
9
+ what.new(*args).tap(&block)
9
10
  end
10
11
 
11
12
  # J-_-L
data/lib/zucker/unary.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Unary = true end
2
3
 
3
4
  class String
4
5
  def +@
data/lib/zucker/union.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'zucker'
2
+ module Zucker Union = true end
2
3
 
3
4
  class Regexp
4
5
  def |(arg)
@@ -1,6 +1,7 @@
1
1
  require 'zucker'
2
2
  require 'date'
3
3
  require 'time'
4
+ module Zucker Version = true end
4
5
 
5
6
  module RubyVersion
6
7
  class << self
data/spec/kernel_spec.rb CHANGED
@@ -27,11 +27,16 @@ describe 'executed_directly?' do
27
27
  end
28
28
 
29
29
  describe 'irb?' do
30
- it 'should return true if called in IRB' do; end
30
+ it 'should return true if called in IRB or RIPL' do; end
31
31
  end
32
32
 
33
33
  describe 'ignore_sigint!' do
34
34
  it 'should catch ctrl+c signals' do; end
35
35
  end
36
36
 
37
+ describe 'ignore_sigquit!' do
38
+ it 'should catch ctrl+\ signals' do; end
39
+ end
40
+
41
+
37
42
  # J-_-L
@@ -21,7 +21,7 @@ describe 'Regexp#visualize' do
21
21
  end.chomp.should == '1: >mail< @example.com'
22
22
  end
23
23
 
24
- it 'should display "group identifier: no match" the arg2 group could not be matched' do
24
+ it 'should display "group identifier: no match" if the arg2 group could not be matched' do
25
25
  capture_stdout do
26
26
  regex.vis 'mail@example.com', 3
27
27
  end.chomp.should == '3: no match'
data/spec/sandbox_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'zucker/sandbox'
2
2
 
3
3
  describe 'sandbox' do
4
- unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
4
+ unless defined?(RUBY_ENGINE) && ( RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx' )
5
5
  it 'should throw a SecurityError if bad commands are issued' do
6
6
  proc do
7
7
  sandbox do