LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-17-2007, 10:44 AM   #1
masternerdguy
LQ Newbie
 
Registered: Jul 2007
Posts: 10

Rep: Reputation: 0
Exclamation str.chomp!


In ruby, what does the line str.chomp! do if str is a string?
 
Old 07-17-2007, 10:56 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
"hello".chomp            #=> "hello"
"hello\n".chomp          #=> "hello"
"hello\r\n".chomp        #=> "hello"
"hello".chomp("llo")     #=> "he"
you should read up a ruby tutorial/book/web page before posting here. it will save you a lot of time.

Last edited by ghostdog74; 07-17-2007 at 10:58 AM.
 
Old 07-17-2007, 12:36 PM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
String#chomp([param]) returns a new string that's the same as the receiver* but with the line endings (or optional parameter) removed from the end.

String#chomp!([param]) modifies the receiver; in other words, it's destructive -- it mutates the original string rather than producing a new one.

Scheme also follows this tradition of putting exclamation marks after destructive functions.

* receiver being the object on which the "method" is called (in Ruby-speak, inheriting from Smalltalk-speak, methods are "messages" and the objects on which they are called are "receivers").
 
Old 07-17-2007, 02:39 PM   #4
masternerdguy
LQ Newbie
 
Registered: Jul 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Thank you. That is all I wanted to know.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: Check if "$str" is of type [A-Z]<char string>[0-9][0-9] introuble Programming 2 06-02-2006 10:33 AM
perl's chomp under Win-Linux thelonius Programming 3 04-12-2006 02:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration