Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialImmo 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.
1 Answer
tobiaskrause
9,160 PointsDo 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
10,515 PointsThanks, I obviously misunderstood chomp. Works just fine now with strip!
Immo Struchholz
10,515 PointsImmo Struchholz
10,515 PointsHere 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