This is more a Ruby than a Rails question -- feel free to redirect me
as appropriate -- but either this is a Ruby 1.9 bug or I have some
serious misunderstanding.  Essentially, I've caught the <=> operator
returning nil -- not -1, 0, or 1, but nil.  Schematically:

class A
  attr_accessor :slot
  fun matches?(s)
    p "s <=> @slot = #{s <=> @slot}"
    return (s <=> @slot) == 0
  end
end

Driven from a script, I get something like this:

# Case 1: Notice that <=> evaluates to nil when it should eval to 0
a.slot = "dog"
a.matches?("dog")
"s <=> @slot = "
=> false

# Case 2: When I pass a String.new("dog") everything works
a.slot = "dog"
a.matches?(String.new("dog"))
"s <=> @slot = 0"
=> true

What's really odd is that called interactively, Case 1 works as
expected.  When called from a script, it exhibits the oddity above.

Am I missing something fundamental about Ruby and string comparison?

- ff

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to