regex - ruby match regular expression -
i'm trying require files in folder. have following.
dir.foreach file.expand_path("app/models") |file| require file unless file === /^\./ end
however, it's failing. when open ruby console, try following:
"." === /^\./
and evaluates false. why won't match?
the ===
operator method of object on left.
the order of operands on ===
matters in case, because if string literal "."
comes first, string equality operator (method) string#===
evaluated. if regex literal placed on left, the regexp operator regexp#===
used:
reverse operands.
# string "." isn't equal regexp object >> "." === /^\./ => false # regexp left operand: >> /^\./ === "." => true # string on left, may use =~ , test nil non-match >> "." =~ /^\./ => 0
Comments
Post a Comment