Larry Forrister <L4 / stetson.net> writes:

> How do you create an in place modification method based on or equivalent to the
> one listed below?  i.e.... proper_case!
> ~~LF
>
> class String
>     def proper_case!
>         # ??????
>     end
>     def proper_case
>         @pc=' '
>         @rs=''
>         self.each_byte{|@ib|
>             @ic=@ib.chr
>             if @pc==' '
>                 @rs<<@ic.upcase
>             else
>                 @rs<<@ic
>             end
>             @pc=@ic
>             }
>         @rs
>     end
> end

You can replace one string value with another with the String#replace
method.

    class String
      def proper_case!
        proper = self.proper_case
        if self != proper
          replace(proper)
        else
          nil
        end
      end
    end

However, I think your methods are better implemented with gsub and
gsub!

    class String
      def proper_case!
        gsub!(/(\A|\s)\w/) { $&.upcase }
      end
      def proper_case
        gsub(/(\A|\s)\w/) { $&.upcase }
      end
    end


-- 
matt