比如 slice! 之类的?
[pre lang="ruby" line="1"]
=begin
slice!(fixnum) → fixnum or nil
slice!(fixnum, fixnum) → new_str or nil
slice!(range) → new_str or nil
slice!(regexp) → new_str or nil
slice!(other_str) → new_str or nil
Deletes the specified portion from str, and returns the portion deleted.
=end
string = "this is a string"
string.slice!(2) #=> "i"
string.slice!(3..6) #=> " is "
string.slice!(/s.*t/) #=> "sa st"
string.slice!("r") #=> "r"
string #=> "thing"
[/pre]
然后顶楼问题我没有重现,不知道是什么情况。我一般是这么写的
[pre lang="ruby" line="1"]IO.foreach('test.txt') do |line|
p line.chomp
end[/pre]