Chop and chop!

hi,

i know for 99% of you this is a very basic question but i was wondering
what the difference between chop and chop! commands are.

thanks

···

--
Posted via http://www.ruby-forum.com/.

Johnathan Smith wrote:

what the difference between chop and chop! commands are.

sorry i meant chomp and chomp!

thanks

···

--
Posted via http://www.ruby-forum.com/\.

quoth the Johnathan Smith:

hi,

i know for 99% of you this is a very basic question but i was wondering
what the difference between chop and chop! commands are.

thanks

Generally with Ruby, methods with the '!' are destructive, and modify the
receiver in place:

s = "foobar\n"

=> "foobar\n"

s.chop

=> "foobar"

s

=> "foobar\n"

s.chop!

=> "foobar"

s

=> "foobar"

...here you can see 'chop' returns a modified copy, leaving 's' intact,
whilst 'chop!' modifies 's' directly.

HTH,
-d

···

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972