chop and chop!

  • Thread starter Johnathan Smith
  • Start date
J

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
 
D

darren kirby

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top