testing equality

  • Thread starter Haris Bogdanovic
  • Start date
H

Haris Bogdanovic

Hi.

When I try to test equality of two strings, for example:

if object1.string==object2.string then puts object1.string end

I get nothing printed even though two strings are equal.

Why ?

Thanks
 
J

Justin Collins

Haris said:
Hi.

When I try to test equality of two strings, for example:

if object1.string==object2.string then puts object1.string end

I get nothing printed even though two strings are equal.

Why ?

Thanks

The best way is to try the code using irb and post the results if you
are still stuck.
Most likely, though, the objects you are comparing not really equal. Try
printing out the values before you compare them.

-Justin
 
R

Robert Klemme

Apparently those objects are not equal.
The best way is to try the code using irb and post the results if you are
still stuck.
Most likely, though, the objects you are comparing not really equal. Try
printing out the values before you compare them.

And when doing that p is preferred to puts because it will reveal any
additional whitespace that you would not see otherwise.

Kind regards

robert
 
H

Haris Bogdanovic

I got it. One string from comparison is from gets function so it has 'enter'
character added on the end.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top