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 trial

Ruby Ruby Basics Objects Classes

Joshgun Huseynov
Joshgun Huseynov
365 Points

Unexpected return type in Ruby

def check(input)
  reversed = input.reverse
  puts reversed
  reversed == input
end

puts check(gets)

Why this code returns false when I prompt "123321" or "helloolleh"?

Lukasz Walczak
Lukasz Walczak
6,620 Points

method returns the result of the last statement evaluation in this case it is boolean value, as the last line of code checks for equality between "reversed" and "input" variables

1 Answer

Basto Biih
Basto Biih
5,334 Points

You made a 1st mistake on the reverse! method by not putting the [!]. Also drop the (input) and just input your string you want before the reverse! method. This is also shown in the video.


def check

reversed = "helloolleh".reverse!

puts reversed

end

puts check