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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -