ruby - "-" == "-" returns false.. Why? -

anybody know whats going on here? why "-" not found? try in irb.
if
string = "(( :h – :2b – :3b – :hr )+( 2 * :2b )+( 3 * :3b )+( 4 * :hr ))/ :ab " string.split(" ")[2] == "-" it returns false well.
the character string.split(" ")[2] –. may normal hyphen, in fact different character normal hyphen: -.
you can see getting ordinal value of each:
string.split(" ")[2].ord # => 8211 "-".ord # => 45 therefore, should checking equality unicode character \u2013:
string.split(" ")[2] == "\u2013" # => true or can replace occurrences of \u2013 -:
string.gsub!("\u2013", "-") string.split(" ")[2] == "-" # => true
Comments
Post a Comment