0

I'm new to ruby and it could be some basic stuff, but it just drives me crazy.

How is the following possible?

    (rdb:1) display $2
    26: $2 = "Alien"

    (rdb:1) display $2 == "Alien"
    27: $2 == "Alien" = false

    (rdb:1) display $2.equal? "Alien"
    28: $2.equal? "Alien" = false

    (rdb:1) display $2.strip.chomp.equal? "Alien"
    29: $2.strip.chomp.equal? "Alien" = false

    (rdb:1) display $2.class
    30: $2.class = String

Ruby 1.9.3p125, Rails 3.1.0, Cucumber 1.1.8

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Grozz
  • 8,317
  • 4
  • 38
  • 53
  • Does this happen in IRb, etc., or just when in ruby-debug? – Andrew Marshall Mar 28 '12 at 06:09
  • Perhaps you should use `(` and `)` just to make sure what you want to check? Ruby tries to guess (well, not the right word here) what you want to say, but using `(` makes it much clearer. – mliebelt Mar 28 '12 at 06:11
  • @AndrewMarshall in ruby-debug and also while running the code itself without debugging – Grozz Mar 28 '12 at 06:17

1 Answers1

0
(rdb:1) display $2[0]
2: $2[0] = "

Mistery solved.

Grozz
  • 8,317
  • 4
  • 38
  • 53
  • 1
    In general, when an "obvious" string comparison fails, I look at... 1. the first character, 2. the last character, and 3. the length, to see if there are some non-printing characters in the string or other general wackyness. – Bob Gilmore Mar 28 '12 at 06:28