lib/rubyc/cli.rb in rubyc-0.1.2 vs lib/rubyc/cli.rb in rubyc-0.1.3

- old
+ new

@@ -90,9 +90,19 @@ desc "uniq", "Enumerable#uniq" def uniq puts $stdin.to_a.uniq end + desc "uniq_by BLOCK", "TODO" + def uniq_by(code = nil) + code ||= "line" + proc = eval("Proc.new{|line| l = line; #{code}}") + counts = $stdin.uniq_by do |line| + proc.call(line.chomp) + end + puts counts + end + desc "compact", "Remove empty lines" def compact $stdin.each{ |line| puts line if line.chomp! != ""} end