Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > chop and chop!

Reply
Thread Tools

chop and chop!

 
 
Johnathan Smith
Guest
Posts: n/a
 
      01-08-2008
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/.

 
Reply With Quote
 
 
 
 
Johnathan Smith
Guest
Posts: n/a
 
      01-08-2008
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/.

 
Reply With Quote
 
 
 
 
darren kirby
Guest
Posts: n/a
 
      01-08-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
chop() and empty() functions Jeremy L. Moles Python 6 05-27-2006 08:55 AM
"chomp,chop" usage i.e. chop immediately after chomp martin Perl Misc 3 04-15-2006 08:09 PM
print chop; VS chop; print; yusufm Perl Misc 2 03-09-2006 12:29 AM
How do I always chop off both query string and "#" from document.location.href? Phil Powell Javascript 8 10-27-2004 09:37 PM
Inverse of 'chop @array' gusmeister Perl 1 03-06-2004 01:28 AM



Advertisments