Not yet a systematic study of Ruby, recently looking at the Metasploit framework of the exploit will involve the Ruby script, it would be very hard to check the data once again to make some notes.
There are built-in functions for chop and chomp in Ruby strings. The usage of ruby strings chop and chomp I get in http://www.w3cschool.cc/ruby/ruby-string.html is described below:
Single from these words, or some unclear white (seemingly borrowed from the Perl language of the chop and chomp functions of the use), and then Baidu a bit, I http://blog.chinaunix.net/uid-20691105-id-1568659.html get the following:
"Hello" = "" "hello\r\n". chomp= "" "hello\n\r". chomp= "" hello\n "=" "hello\r". chomp= "" "Hello". Chomp ("llo") = "" "" he "=" "string\r\n". chop= "" "string" = "" "string\n\r". chop= "" "string\n" = "" string\n ". chop=" "" string ". chop=" "Strin" < = "Span=" ">
I try the string above on this machine one by one, and the output is as follows:
First, you can see that print does not output line breaks (no wrapping), but resolves the escape characters in double quotes, and you can see that print output the newline character in the string \ n and carriage return \ r. I was a little puzzled by the "\ r \ n", "\n\r" The two sequence is not the same, chop and chomp function is how to deal with. From the result of the operation, when the last side of the string is "\ r \ n", "\ r \ n" will be removed, and when the string is followed by "\n\r", only the carriage return will be removed. Well, it's finally clear.
Ruby Learning Notes (2) the difference between-chomp,chop