From: Brian Candler Date: 2012-09-25T01:23:05+09:00 Subject: Re: How would you allow variable from specific list of Fixnum? Eliezer Croitoru wrote in post #1077009: > If there is not difference in the operation such as in: > newregex = /[\d]+/ > newregex = Regexp.new("[\\d]+") > > so there is not really a good reason to use one or the other since the > result is the same. In the first, you are using a Regexp literal. This is immutable, and you will get the same object_id each time round a loop. In the second, inside Regexp.new you are using a string literal - which is mutable and gets a different object_id each time round a loop. And therefore a new Regexp has to be built each time, because Ruby doesn't know that the String actually has the same contents. >> 3.times { puts /\d+/.object_id; puts Regexp.new("/\\d+/").object_id } 2165193160 2165191640 2165193160 2165191560 2165193160 2165191480 -- Posted via http://www.ruby-forum.com/.