bin/rubyc in rubyc-0.0.9 vs bin/rubyc in rubyc-0.0.10
- old
+ new
@@ -32,47 +32,47 @@
class Rubyc < Thor
desc :map, "Apply Enumerable#map on each line"
def map(code)
proc = eval( "Proc.new{|line| l = line; #{code}}" )
STDIN.map do |line|
- puts proc.call(line).to_s
+ puts proc.call(line.chomp).to_s
end
end
desc :sum, "Calculate the sum of Numeric expressed on each line"
def sum(code = nil)
code ||= "line"
proc = eval("Proc.new{|line| l = line; #{code}}")
sum = STDIN.sum do |line|
- proc.call(line).to_f
+ proc.call(line.chomp).to_f
end
puts sum
end
desc :select, "Apply Enumerable#select on each line"
def select(code)
proc = eval( "Proc.new{|line| l = line; #{code}}" )
STDIN.map do |line|
- puts line if proc.call(line)
+ puts line if proc.call(line.chomp)
end
end
desc :count_by, "Count by"
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
+ proc.call(line.chomp)
end
puts counts.to_yaml
end
desc :sort_by, "Sort by"
def sort_by(code = nil)
code ||= "line"
proc = eval( "Proc.new{|line| l = line; #{code}}" )
counts = STDIN.sort_by do |line|
- proc.call(line)
+ proc.call(line.chomp)
end
puts counts
end
desc :grep, "Grep"