Robert Klemme wrote:
> On 01/04/2010 10:27 AM, Ruby Newbee wrote:
>> Sometime I saw you wrote regex =~ string, while sometime you wrote
>> string =~ regex.
>> What's their difference and what's the recommended way? Thanks.
> 
> The first version invokes method Regexp#=~ and the second version
> invokes String#=~ - which happen to do roughly the same although I
> believe the second one to be a tad slower.  I personally prefer the
> first form because of the speed difference and regular expression
> matching is rather an operation of Regexp than of String.

Interesting.  Whereas I prefer the second because I think
mystring =~ /foo/
is syntactically analogous to
mystring == 'foo'

> 
> Kind regards
> 
>   robert

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen / marnen.org
-- 
Posted via http://www.ruby-forum.com/.