From: Morton Goldberg Date: 2007-07-20T09:19:35+09:00 Subject: Re: regex backreference weirdness... On Jul 19, 2007, at 6:23 PM, Kyle Schmitt wrote: > Below is what I tried, which leads me up to the question of... what > would the _right_ way be of doing this? > > irb>"camel_case".gsub(/_(.)/,$1.upcase) > NoMethodError: undefined method `upcase' for nil:NilClass > from (irb):1 I think, in this case, you will have to use a block. For example: "camel_case".gsub(/_(.)/) { $1.upcase } # => "camelCase" or "camel_case".gsub(/_./) { |m| m[1, 1].upcase } # => "camelCase" Regards, Morton