Can someone explain what's happening here? (String#gsub question)

I read the caveat in the pickaxe about when the replacement is a
string, but I don’t understand this. (I’m sure it’s working as
designed, I just don’t “get it”.)

What’s going on here?

“hello”.gsub(/([aeiou])/, ‘<\1>’) => hll

“hello”.gsub(/([aeiou])/, “<\1>”) => h<^A>ll<^A>

ruby -v yields:
ruby 1.7.2 (2002-06-29) [i386-mswin32]

···

Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com

Hi,

···

In message “Can someone explain what’s happening here? (String#gsub question)” on 03/04/09, Michael Campbell michael_s_campbell@yahoo.com writes:

What’s going on here?

“hello”.gsub(/([aeiou])/, ‘<\1>’) => hll

“hello”.gsub(/([aeiou])/, “<\1>”) => h<^A>ll<^A>

\1 in double quoted string is considered as \001 (^A) before reaching
gsub.

						matz.

Ok, I get that; thanks. “<\1>” did what I expected.

···

— Yukihiro Matsumoto matz@ruby-lang.org wrote:

Hi,

In message “Can someone explain what’s happening here? (String#gsub > question)” > on 03/04/09, Michael Campbell michael_s_campbell@yahoo.com > writes:

What’s going on here?

“hello”.gsub(/([aeiou])/, ‘<\1>’) => hll

“hello”.gsub(/([aeiou])/, “<\1>”) => h<^A>ll<^A>

\1 in double quoted string is considered as \001 (^A) before
reaching gsub.


Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more