Ruby 2 syntax, $ ` -
i've sound chunk of code, , can not understand syntax. , can not make search. code is
keys.map { |k| k =~ /\./; $` }
what mean $` ? tried play in console, did not understood how works
when using regex match string, $` matches string before current match. so:
irb> "hello world".match(/world/) => #<matchdata "world"> irb> $` => "hello "
i should add ruby doc reference: http://ruby-doc.org/core-2.0.0/doc/globals_rdoc.html
more info: if use 'english' library, ` can replaced word prematch:
irb> "hello world".match(/world/) => #<matchdata "world"> irb> $` => "hello " irb> $prematch => nil irb> require 'english' => true irb> $prematch => "hello " irb>
Comments
Post a Comment