Search code examples
rubystringruby-debug

Ruby string comparison against regex capture


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


Solution

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

    Mistery solved.