自己常用的ruby小函数,贴一下
作者:半瓶墨水 链接:http://www.2maomao.com/blog/ruby-small-general-procs/
下载: ggg.rb
#does ruby guy notice about this pain?
def reverse_slash(str)
str.gsub(/\//) { |x| "\\" }
end
#double-quote str
def dquote(str)
"\"#{str}\""
end
#execute and wait for each line
def execute_and_watch(str)
putsflush " command:#{str}"
IO.popen(str).each {|line| yield line}
end
#log to the $stderr
def logerr(str)
#we might need to set the error log file and output log file in the future
$stderr.putsflush "ERROR! " + str
end
#puts to the $stdout and flush
def putsflush(*str)
puts *str
$stdout.flush
end
def reverse_slash(str)
str.gsub(/\//) { |x| "\\" }
end
#double-quote str
def dquote(str)
"\"#{str}\""
end
#execute and wait for each line
def execute_and_watch(str)
putsflush " command:#{str}"
IO.popen(str).each {|line| yield line}
end
#log to the $stderr
def logerr(str)
#we might need to set the error log file and output log file in the future
$stderr.putsflush "ERROR! " + str
end
#puts to the $stdout and flush
def putsflush(*str)
puts *str
$stdout.flush
end
555,本篇现在一条评论也没有,雁过留声,人过留名,各位乡亲父老,有钱的捧个钱场,没钱的捧个人场......
发表评论
Additional comments powered by BackType


