bin/rubyc in rubyc-0.0.10 vs bin/rubyc in rubyc-0.0.11

- old
+ new

@@ -9,19 +9,21 @@ memo[key] += 1 memo end end + # This method was borrowed from ActiveSupport code def group_by self.inject({}) do |memo, elem| key = yield elem memo[key] ||= [] memo[key] << elem memo end end - + + # File activesupport/lib/active_support/core_ext/enumerable.rb, line 57 def sum(identity = 0, &block) if block_given? map(&block).sum(identity) else inject { |sum, element| sum + element } || identity @@ -49,16 +51,16 @@ end desc :select, "Apply Enumerable#select on each line" def select(code) proc = eval( "Proc.new{|line| l = line; #{code}}" ) - STDIN.map do |line| + STDIN.each do |line| puts line if proc.call(line.chomp) end end - desc :count_by, "Count by" + desc :count_by, "Count the number of lines that have the same property. The property is defined by the return value of the given the block" def count_by(code = nil) code ||= "line" proc = eval( "Proc.new{|line| l = line; #{code}}" ) counts = STDIN.count_by do |line| proc.call(line.chomp) @@ -96,10 +98,10 @@ puts STDIN.to_a.uniq end desc :compact, "Remove empty lines" def compact - puts STDIN.select{|line| line.strip != ""} + STDIN.each{|line| puts line if line.strip != ""} end desc :merge, "Merge consecutive lines" def merge(nb_lines, sep = ",") STDIN.each_slice(nb_lines.to_i){|chunk| puts chunk.map{|elem| elem.strip}.join(sep) }