[MacRuby-devel] Comparison between String and nil fails.

Michel Steuwer michel.steuwer at onlinehome.de
Wed May 5 02:11:26 PDT 2010


Hi everyone,
yesterday i migrated my little MacRuby project to 0.6 and i found a kind of strange behavior in a comparison between a string and nil. In MacRuby 0.5 the line worked as expected.
I get the following error message in a comparison between a string on the left and nil on the right:
can't convert nil into String (TypeError)

I made a little demo project to show the problem.
The string i want to compare comes out of a userInfo dictionary i get when iTunes send a notification through the NSDistributredNotificationCenter.
In the demo project the error occurs, if you play, pause, or skip a song in iTunes (every time i get a notification from iTunes).

So here the code in which the error occurs:

def songChanged(notification)
	NSLog("notification.userInfo[Name]		#{notification.userInfo['Name']}.")
	NSLog("notification.userInfo[Name].nil?		#{notification.userInfo['Name'].nil?}.")
	NSLog("notification.userInfo[Name].class	#{notification.userInfo['Name'].class}.")
	NSLog("notification.userInfo[Name] != nil	#{notification.userInfo['Name'] != nil}")
end

The method receives a notification from iTunes and the last line in the method fails ( notification.userInfo['Name'] != nil ).

I don't know where the problem is, but i guess the comparison should just return false. One again, in MacRuby 0.5 the line worked as expected.

You can find the hole demo project at:
http://github.com/michelSt/MacRubyBug

Thanks,
Michel
--
Michel Steuwer     |     michel.steuwer at onlinehome.de

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100505/4223c006/attachment-0001.html>


More information about the MacRuby-devel mailing list