Permalink
Browse files

Ruby Zucker 7 :)

  • Loading branch information...
1 parent 7f7dd65 commit 1a66c5e110865d4b3febc9bdfc7aaaeb19b52127 @janlelis committed Oct 3, 2010
Showing with 5,557 additions and 4 deletions.
  1. +17 −0 desc/7/alias_for.yaml
  2. +18 −0 desc/7/aliases.yaml
  3. +13 −0 desc/7/array.yaml
  4. +16 −0 desc/7/array2proc.yaml
  5. +23 −0 desc/7/binding.yaml
  6. +9 −0 desc/7/blank.yaml
  7. +10 −0 desc/7/cc.yaml
  8. +11 −0 desc/7/class2proc.yaml
  9. +23 −0 desc/7/dd.yaml
  10. +15 −0 desc/7/egonil.yaml
  11. +15 −0 desc/7/engine.yaml
  12. +10 −0 desc/7/enumerable.yaml
  13. +14 −0 desc/7/hash.yaml
  14. +10 −0 desc/7/hash2proc.yaml
  15. +20 −0 desc/7/info.yaml
  16. +16 −0 desc/7/iterate.yaml
  17. +19 −0 desc/7/ivars.yaml
  18. +14 −0 desc/7/kernel.yaml
  19. +11 −0 desc/7/mcopy.yaml
  20. +16 −0 desc/7/mm.yaml
  21. +11 −0 desc/7/not.yaml
  22. +10 −0 desc/7/oo.yaml
  23. +19 −0 desc/7/os.yaml
  24. +11 −0 desc/7/qq.yaml
  25. +12 −0 desc/7/regexp2proc.yaml
  26. +18 −0 desc/7/sandbox.yaml
  27. +22 −0 desc/7/square_brackets_for.yaml
  28. +23 −0 desc/7/string.yaml
  29. +16 −0 desc/7/tap.yaml
  30. +15 −0 desc/7/unary.yaml
  31. +10 −0 desc/7/union.yaml
  32. +28 −0 desc/7/version.yaml
  33. +2,538 −0 doc/7/zucker_doc.html
  34. +555 −0 doc/7/zucker_doc.rb
  35. +8 −3 doc/zucker_doc.html
  36. +1 −1 lib/zucker.rb
  37. +21 −0 lib/zucker/7/alias_for.rb
  38. +51 −0 lib/zucker/7/aliases.rb
  39. +4 −0 lib/zucker/7/all.rb
  40. +25 −0 lib/zucker/7/array.rb
  41. +18 −0 lib/zucker/7/array2proc.rb
  42. +34 −0 lib/zucker/7/binding.rb
  43. +28 −0 lib/zucker/7/blank.rb
  44. +25 −0 lib/zucker/7/cc.rb
  45. +12 −0 lib/zucker/7/class2proc.rb
  46. +4 −0 lib/zucker/7/control.rb
  47. +23 −0 lib/zucker/7/dd.rb
  48. +4 −0 lib/zucker/7/debug.rb
  49. +4 −0 lib/zucker/7/default.rb
  50. +27 −0 lib/zucker/7/egonil.rb
  51. +68 −0 lib/zucker/7/engine.rb
  52. +14 −0 lib/zucker/7/enumerable.rb
  53. +4 −0 lib/zucker/7/env.rb
  54. +4 −0 lib/zucker/7/extensions.rb
  55. +27 −0 lib/zucker/7/hash.rb
  56. +16 −0 lib/zucker/7/hash2proc.rb
  57. +192 −0 lib/zucker/7/info.rb
  58. +27 −0 lib/zucker/7/iterate.rb
  59. +28 −0 lib/zucker/7/ivars.rb
  60. +34 −0 lib/zucker/7/kernel.rb
  61. +10 −0 lib/zucker/7/mcopy.rb
  62. +34 −0 lib/zucker/7/mm.rb
  63. +19 −0 lib/zucker/7/not.rb
  64. +4 −0 lib/zucker/7/object.rb
  65. +17 −0 lib/zucker/7/oo.rb
  66. +54 −0 lib/zucker/7/os.rb
  67. +12 −0 lib/zucker/7/qq.rb
  68. +12 −0 lib/zucker/7/regexp2proc.rb
  69. +25 −0 lib/zucker/7/sandbox.rb
  70. +4 −0 lib/zucker/7/shortcuts.rb
  71. +21 −0 lib/zucker/7/square_brackets_for.rb
  72. +54 −0 lib/zucker/7/string.rb
  73. +11 −0 lib/zucker/7/tap.rb
  74. +4 −0 lib/zucker/7/to_proc.rb
  75. +24 −0 lib/zucker/7/unary.rb
  76. +16 −0 lib/zucker/7/union.rb
  77. +118 −0 lib/zucker/7/version.rb
  78. +117 −0 spec/7/alias_for_spec.rb
  79. +13 −0 spec/7/aliases_spec.rb
  80. +12 −0 spec/7/array2proc_spec.rb
  81. +23 −0 spec/7/array_spec.rb
  82. +6 −0 spec/7/binding_spec.rb
  83. +20 −0 spec/7/blank_spec.rb
  84. +6 −0 spec/7/cc_spec.rb
  85. +9 −0 spec/7/class2proc_spec.rb
  86. +37 −0 spec/7/dd_spec.rb
  87. +26 −0 spec/7/egonil_spec.rb
  88. +11 −0 spec/7/engine_spec.rb
  89. +8 −0 spec/7/enumerable_spec.rb
  90. +12 −0 spec/7/hash2proc_spec.rb
  91. +25 −0 spec/7/hash_spec.rb
  92. +8 −0 spec/7/info_spec.rb
  93. +54 −0 spec/7/iterate_spec.rb
  94. +20 −0 spec/7/ivars_spec.rb
  95. +37 −0 spec/7/kernel_spec.rb
  96. +13 −0 spec/7/mcopy_spec.rb
  97. +6 −0 spec/7/mm_spec.rb
  98. +8 −0 spec/7/not_spec.rb
  99. +6 −0 spec/7/oo_spec.rb
  100. +37 −0 spec/7/os_spec.rb
  101. +19 −0 spec/7/qq_spec.rb
  102. +9 −0 spec/7/regexp2proc_spec.rb
  103. +26 −0 spec/7/sandbox_spec.rb
  104. +18 −0 spec/7/spec_helper.rb
  105. +59 −0 spec/7/square_brackets_for_spec.rb
  106. +65 −0 spec/7/string_spec.rb
  107. +19 −0 spec/7/tap_spec.rb
  108. +26 −0 spec/7/unary_spec.rb
  109. +17 −0 spec/7/union_spec.rb
  110. +55 −0 spec/7/version_spec.rb
View
@@ -0,0 +1,17 @@
+alias_for:
+ summary: 'A different way to create aliases: Reversed order and you can pass multiple alias names.'
+ why: "It's clearer in which order to put the arguments."
+ methods:
+ alias_for, aliases_for: |
+ alias_for :methods, :ms # creates an alias for the method :methods with the name ms
+ module Enumerable
+ aliases_for :zip, :with, :%
+ end # creates multiple aliases
+ Module#method_alias_for, Module#method_aliases_for: |
+ # same as alias_for, but using Module#alias_method instead of alias
+ info:
+ - Thanks to Kristian Mandrup for the idea and alias method specs.
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,18 @@
+aliases:
+ summary: Some convenient aliases (and constants) for existing methods.
+ methods:
+ Object#is_an?: Object.is_a?
+ Enumerable#with: Enumerable#zip
+ Enumerable#%: Enumerable#zip
+ Array#**: Array#product
+ Hash#+: Hash#merge
+ Binding#[]: Binding#eval
+ File.filename: File.basename
+ Dir.join: File.join
+ Dir.split: File.split
+ Infinity: 1.0 / 0.0
+ NaN: 0.0 / 0.0
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,13 @@
+array:
+ summary: Methods one could miss for ⇧Array⇧.
+ why:
+ - ⇧Array⇧ has ⇧&⇧ and ⇧|⇧, but why does it not have ⇧^⇧?
+ - ⇧sum⇧ is just needed pretty often..
+ methods:
+ Array#^: "[1,2,3,4] ^ [3,4,5,6] # => [1,2,5,6]"
+ Array#sum: "[1,2,3,4,5].sum # => 15"
+ Array#chrs: "[72, 97, 108, 108, 111].chrs # => 'Hallo'"
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,16 @@
+array2proc:
+ summary: Calls the method named by the first paramenter and passes the other elements as paramaters.
+ why: When using ⇧Symbol#to_proc⇧, you often wish to pass parameters.
+ methods:
+ Array#to_proc: |
+ [1,2,3,4].map &[:*, 5] # => [5, 10, 15, 20]
+ # you can also chain them, if the first parameter is an Array
+ [1,2,3,4].map &[[:to_s, 2],[:+, 'b']] # => ["1b", "10b", "11b", "100b"]
+ info:
+ - Inspired by →this article→http://www.sanityinc.com/articles/adding-array-to-proc-to-ruby→.
+ - "More about →to_proc→http://rbjl.net/29-become-a-proc-star→."
+ - Chaining inspired by →eregon→http://github.com/eregon/Classes/blob/master/to_proc.rb→.
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,23 @@
+binding:
+ summary: Adds a verbose ⇧Binding#inspect⇧.
+ why: It gives you information about the current environment variables.
+ methods:
+ Binding#inspect, v, vv: |
+ # shows your current environment's variables, irb example:
+ >> a=3
+ => 3
+ >> binding
+ => #<Binding:0x94c4b50>
+ local vars
+ - a: 3
+ - _: #<Binding:0x94c4b50>
+ (instance vars)
+ - none
+ self
+ - main
+ block_given?
+ - false
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,9 @@
+blank:
+ summary: Does pretty the same as in ActiveSupport (Every object can be asked if it is blank).
+ why: It's too familiar ;)
+ methods:
+ Object#blank?: "'an object'.blank? # => false"
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,10 @@
+cc:
+ summary: ⇧c⇧ outputs the current method callstack.
+ methods:
+ c, cc: |
+ c # shows the method callstack
+ c true # do not hide irb callstack
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,11 @@
+class2proc:
+ summary: Creates a new instance of the class.
+ methods:
+ Class#to_proc: "[ [1,2],[3,5,6,7,3] ].map(&Set) # => [ Set[1,2], Set[5,6,7,3] ]"
+ info:
+ - Inspired by Ruby Facets.
+ - "More about →to_proc→http://rbjl.net/29-become-a-proc-star→."
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,23 @@
+dd:
+ summary: Easy debug printing with the ⇧p⇧ alternative ⇧.d⇧. It outputs to stdout and returns ⇧self⇧. Accepts a block.
+ methods:
+ Object#d, Object#dd: |
+ some.d.methods.d.noone.d.knows.d
+ # ...outputs 4 lines with the inspected objects
+ # => (result)
+
+ 21+Math.sin(42).d
+ # outputs -0.916521547915634
+ # => 20.0834784520844
+
+ name = 'Earth'
+ 'Hello ' + name.d{|e| "The length is: #{e.size}"}
+ # outputs "The length is: 5"
+ # => 'Hello Earth'
+ info:
+ - "This is inspired by the →⇧.tap⇧ method→http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions→."
+ - There is also ⇧tap⇧ cube with more ⇧tap⇧ methods.
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,15 @@
+egonil:
+ summary: Creates a block, where ⇧nil⇧ does not raise ⇧NoMethodError⇧s.
+ methods:
+ egonil, nn: |
+ egonil do
+ nil.some_methods.that[:do].not.exist
+ end # => nil
+
+ nn{ nil.some_methods.that[:do].not.exist } # => nil
+ info:
+ - See →this post→http://rbjl.net/26-the-28-bytes-of-ruby-joy→ for more information and discussion.
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,15 @@
+engine:
+ summary: Adds a ⇧RubyEngine⇧ class for easy compatibility checks.
+ methods:
+ RubyEngine: |
+ RubyEngine: "# outputs the interpreter name"
+ RubyEngine.mri?: "RubyEngine.mri? # true if using the official Ruby interpreter"
+ RubyEngine.jruby?: "RubyEngine.jruby? # true if using JRuby"
+ RubyEngine.rubinius?: "RubyEngine.rubinius? # true if using rubinius"
+ RubyEngine.ree?: "RubyEngine.ree? # true if using enterprise edition"
+ RubyEngine.ironruby?: "RubyEngine.ironruby? # true if using IronRuby"
+ RubyEngine.macruby?: "RubyEngine.macruby? # true if using MacRuby"
+ RubyEngine.cardinal?: "RubyEngine.cardinal? # true if using parrot"
+ versions:
+ - 1.9
+ - 1.8
View
@@ -0,0 +1,10 @@
+enumerable:
+ summary: ⇧Enumerable⇧ extensions.
+ methods:
+ Enumerable#mash: "[1,2,3].mash{|e| [e, e.to_s] } # => {1=>'1',2=>'2',3=>'3'}"
+ info:
+ - Inspired by Ruby Facets' ⇧mash⇧.
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,14 @@
+hash:
+ summary: Some sugar for dealing with hashs.
+ methods:
+ Hash.zip: "Hash.zip [1,2,3], [4,5,6] # => {1=>4, 2=>5, 3=>6}"
+ Hash#<<: |
+ {1=>2} << [3, 4] # => { 1=>2, 3=>4 }
+ {1=>2} << { 5=>6 } # => { 1=>2, 5=>6 }
+ Hash#&: "{ 1=>4, 2=>5, 3=>6 } & { 1=>4, 2=>7 } # => { 1=>4 }"
+ info:
+ - Some of the operators are inspired by Ruby Facets.
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,10 @@
+hash2proc:
+ summary: Use a hash to apply procs to specific objects.
+ methods:
+ Hash#to_proc: "[1,2,3,4].map(&{\n2 => lambda {|e| e + 1000},\n4 => :to_s,\n}) # => [1, 1002, 3, '4']"
+ info:
+ - "More about →to_proc→http://rbjl.net/29-become-a-proc-star→."
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,20 @@
+info:
+ summary: Access environment information with the ⇧Info⇧ module.
+ why: "You don't need to remember in which global variable, constant or special method the information you are searching for is hidden."
+ methods:
+ Info: |
+ # for example
+ Info.working_directory # Dir.pwd
+ Info.load_path # $:
+ Info.platform # RUBY_PLATFORM
+ Info.current_file # similar to __FILE__
+ # you could also add them to the global namespace with: include Info
+ # see the source file for the list of accessors or
+ Info.list
+ info:
+ - Please note that it is not possible to put some of __THOSE_KEYWORDS__ in methods, so the result might slightly differ. This might affect ⇧current_file⇧, ⇧current_file_directory⇧, ⇧current_line⇧ and ⇧current_method⇧.
+ - Thanks to Facets for the ⇧caller⇧ Regexp.
+ versions:
+ - 1.9
+ - 1.8 (not all information)
+
View
@@ -0,0 +1,16 @@
+iterate:
+ summary: Iterate over one or more collections.
+ why: "It's like ⇧.each⇧ with two differences: It feels more like a control structure and you can easily iterate over multiple objects."
+ methods:
+ iterate: |
+ iterate [1,2], [3,4,5] do |e,f|
+ puts "#{e},#{f}"
+ end
+ # outputs
+ # 1,3
+ # 2,4
+ # ,5
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,19 @@
+ivars:
+ summary: This method lets you easily assign lots of instance variables.
+ why: |
+ Often, you have to write boilerplate code for assigning instance varialbles, for example this one:
+ ⇧def initialize(variable1, variable2)
+   @variable1, @variable2 = variable1, variable2
+ end⇧
+ methods:
+ instance_variables_from, ivars: |
+ def a_method(a = 1, b = 2)
+ instance_variables_from binding # assigns @a and @b
+
+ params = {:c => 3, :d => 4}
+ instance_variables_from params # # assigns @c and @d
+ end
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,14 @@
+kernel:
+ summary: Some useful general shortcut methods.
+ why: Readability.
+ methods:
+ activate_warnings!: "activate_warnings! # sets $VERBOSE to 1"
+ deactivate_warnings!: "deactivate_warnings! # sets $VERBOSE to 0"
+ executed_directly?, standalone?: "executed_directly? # checks, if the current file is run directly -> true"
+ library?: "library? # checks, if the current file is run directly -> false"
+ irb?: "irb? # returns false if not called from IRB"
+ ignore_sigint!: "ignore_sigint! # blocks CTRL+C"
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,11 @@
+mcopy:
+ summary: Adds ⇧Object#mcopy⇧ to create a deep copy using ⇧Marshal⇧.
+ why: Every Ruby book describes, you can do ⇧Marshal.load Marshal.dump object⇧ to create a deep copy... But who needs this verbose syntax in everyday coding?
+ methods:
+ Object#mcopy: |
+ a = %w[hello world]
+ b = a.mcopy
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,16 @@
+mm:
+ summary: ⇧m⇧ displays an ordered public method list.
+ why: See one object's methods without those rarely used inherited methods.
+ methods:
+ Object#m, Object#mm, Object#method_list: |
+ 'test'.m 2 # outputs the list (2 levels deep), for example:
+ String
+ [:<=>, :==, :===, :eql?, :hash, :casecmp, :+, :*, :%, :[], :[]=, :insert, :length, :size, :bytesize, :empty?, :=~, :match, :succ, :succ!, :next, :next!, :upto, :index, :rindex, :replace, :clear, :chr, :getbyte, :setbyte, :to_i, :to_f, :to_s, :to_str, :inspect, :dump, :upcase, :downcase, :capitalize, :swapcase, :upcase!, :downcase!, :capitalize!, :swapcase!, :hex, :oct, :split, :lines, :bytes, :chars, :codepoints, :reverse, :reverse!, :concat, :<<, :crypt, :intern, :to_sym, :ord, :include?, :start_with?, :end_with?, :scan, :ljust, :rjust, :center, :sub, :gsub, :chop, :chomp, :strip, :lstrip, :rstrip, :sub!, :gsub!, :chop!, :chomp!, :strip!, :lstrip!, :rstrip!, :tr, :tr_s, :delete, :squeeze, :count, :tr!, :tr_s!, :delete!, :squeeze!, :each_line, :each_byte, :each_char, :each_codepoint, :sum, :slice, :slice!, :partition, :rpartition, :encoding, :force_encoding, :valid_encoding?, :ascii_only?, :unpack, :encode, :encode!, :to_r, :to_c, :blank?, :^, :lchomp, :lchomp!, :ords, :constantize, :+@, :-@, :|]
+ Comparable
+ [:==, :>, :>=, :<, :<=, :between?]
+ info:
+ - See →this article→http://rbjl.net/31-the-multi-mega-method-list→ for more information.
+ versions:
+ - 1.9
+ - 1.8 (returns strings instead of symbols)
+
View
@@ -0,0 +1,11 @@
+not:
+ summary: ⇧not⇧ returns an object on which all methods are redirected to it's receiver object, but returns inverted boolean.
+ why: Better readability.
+ methods:
+ Object#not: |
+ [1,2,3].not.empty? # true
+ info:
+ - See →this article by Jay Field→http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html→ for more information.
+ versions:
+ - 1.9
+
View
@@ -0,0 +1,10 @@
+oo:
+ summary: The ⇧o⇧ method outputs the current method, line, file and label (if given).
+ methods:
+ o, oo: |
+ o # e.g: Reached method `irb_binding', line 1 of file (irb)
+ o:Label # e.g: Label: reached method `abc', line 7 of file (irb)
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,19 @@
+os:
+ summary: Detect the operating system.
+ why: Checking for ⇧RUBY_PLATFORM⇧ does not report the OS when using JRuby and for better readability.
+ methods:
+ OS: "# displays the operating system"
+ OS.linux?: "OS.linux? # true if you are on a linux machine"
+ OS.mac?: "OS.mac? # true for macs"
+ OS.bsd?: "OS.bsd? # true for bsds"
+ OS.windows?: "include OS; windows? # true for windows. Example of including OS to get the os methods into the global namespace"
+ OS.solaris?: "OS.solaris? # true for solaris/sunos"
+ OS.posix?: "OS.posix? # true if system is posix compatible"
+ OS.is?: "OS.is? /win/ # matches the regex against the os string"
+ info:
+ - This cube depends on system information and may not be 100% accurate.
+ - "Syntax and semantic inspired by Roger Pack's →os gem→http://github.com/rdp/os→."
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,11 @@
+qq:
+ summary: The ⇧q⇧ method does the same like ⇧p⇧, but puts out multiple arguments on the same line.
+ methods:
+ q, qq: |
+ q "zucker", '', {6=>7}, 5, 2.3, :o # outputs "zucker" "" {6=>7} 5 2.3 :o
+ info:
+ - Inspired by →rdp→http://github.com/rdp/sane/blob/master/lib/sane/pps.rb→.
+ versions:
+ - 1.9
+ - 1.8
+
View
@@ -0,0 +1,12 @@
+regexp2proc:
+ summary: Use ⇧&/regex/⇧ to match it against strings.
+ methods:
+ Regexp#to_proc: |
+ %w|just another string array|.map &/[jy]/ # => ["j", nil, nil, "y"]
+ %w|just another string array|.select &/[jy]/ # => ["just", "array"]
+ info:
+ - "More about →to_proc→http://rbjl.net/29-become-a-proc-star→."
+ versions:
+ - 1.9
+ - 1.8
+
Oops, something went wrong.

0 comments on commit 1a66c5e

Please sign in to comment.