chop and chop!

Discussion in 'Ruby' started by Johnathan Smith, Jan 8, 2008.

  1. 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, Jan 8, 2008
    #1
    1. Advertising

  2. 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/.
    Johnathan Smith, Jan 8, 2008
    #2
    1. Advertising

  3. Johnathan Smith

    darren kirby Guest

    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
    darren kirby, Jan 8, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gusmeister

    Inverse of 'chop @array'

    gusmeister, Mar 6, 2004, in forum: Perl
    Replies:
    1
    Views:
    677
    J├╝rgen Exner
    Mar 6, 2004
  2. Jeremy L. Moles

    chop() and empty() functions

    Jeremy L. Moles, May 26, 2006, in forum: Python
    Replies:
    6
    Views:
    3,672
    John Machin
    May 27, 2006
  3. Phil Powell
    Replies:
    8
    Views:
    435
    Phil Powell
    Oct 27, 2004
  4. yusufm

    print chop; VS chop; print;

    yusufm, Mar 9, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    108
    Tad McClellan
    Mar 9, 2006
  5. martin
    Replies:
    3
    Views:
    170
    Joe Smith
    Apr 15, 2006
Loading...

Share This Page