Forum: Ruby string comparison

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Boris G. (Guest)
on 2005-12-15 01:45
(Received via mailing list)
Hi,

I have a class containing a string as an instance variable and I have a
local
variable containing a string.

I compare these two strings with '==' and with the .eql? method:

###################################

obj.text = "hello world"
localtext = "hello world"

if obj.text == localtext
then
	# do something
end

###################################

The condition never became true in my program. Thus I added some debug
output.
This is the the debugging code:

if not obj.text == localtext
then
	print "\"#{obj.text}\" is not equal \"#{localtext}\"\n"
end

This is, what it gave me:

"hello world" is not equal "hello world"

It's not worth trying the example above, since it's not the actual code.
The
actual code in my project is much more complex, that's why I used this
example
to discribe my problem.

Fact is that when the string comparison does not succeed I get an output
like

"hello world" is not equal "hello world"

Now it's your turn... What could cause this behaviour?

thanks and greets

Boris


P.S. I have cancelled two versions of this posting, since they contained
some
typos and syntax errors
unknown (Guest)
on 2005-12-15 06:07
(Received via mailing list)
Hi --

On Thu, 15 Dec 2005, Boris G. wrote:

> localtext = "hello world"
> This is the the debugging code:
> It's not worth trying the example above, since it's not the actual code. The
> actual code in my project is much more complex, that's why I used this
> example
> to discribe my problem.

Well... but showing some working code that doesn't illustrate the
problem isn't going to help us help you :-)

I wonder whether this .text method is return an object other than a
plain String -- perhaps an object with == redefined.


David

--
David A. Black
removed_email_address@domain.invalid

"Ruby for Rails", forthcoming from Manning Publications, April 2006!
This topic is locked and can not be replied to.