自己常用的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
  • Share/Bookmark

555,本篇现在一条评论也没有,雁过留声,人过留名,各位乡亲父老,有钱的捧个钱场,没钱的捧个人场......

发表评论

  • :l
  • :)
  • :q
  • :(
  • :^
  • :x
  • :v
  • :D
  • :s
  • :h
  • :e
  • :X
  • :k
  • :w
  • :d
  • :p

注意:评论中需包含至少一个中文字,否则视为无效

Additional comments powered by BackType