Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Operators and Control Structures Ruby Control Structures The Ruby Else Statement

Immo Struchholz
Immo Struchholz
10,515 Points

.chomp not working?

Hi,

When I call .chomp on a string it doesn't do anything. For example: "something ".chomp just returns "something " but shouldn't it return "something" ?

I wrapped the code from this video in a function like so:

def myName(name)
    if name.chomp.capitalize == "Immo"
        puts "That's my name, too!"
    else
        puts "Hi #{name.capitalize}!"
    end
end

and when I call myName("immo ") it returns: "Hi Immo !" instead of: "That's my name, too!"

Maybe I misunderstood what .chomp does, but I thought it removed trailing whitespace, such as spaces.

Immo Struchholz
Immo Struchholz
10,515 Points

Here is a screenshot of the code (the second function), because my formatting obviously didn't get applied to my post
http://i.imgur.com/cu92vx3.png

1 Answer

Do you really call "immo " (With whitespace)? Seems like you missunderstood chomp. Here is a description: http://ruby-doc.org/core-2.2.0/String.html#method-i-chomp

this is what you are looking for: http://ruby-doc.org/core-2.2.0/String.html#method-i-strip

Immo Struchholz
Immo Struchholz
10,515 Points

Thanks, I obviously misunderstood chomp. Works just fine now with strip!