El Viernes, 20 de Febrero de 2009, Jeff Schwab escribió:
> Iñaki Baz Castillo wrote:
> >   string = "%61lice"
> >   string = eval %{ "#{ string.gsub(/%/,'\x') }" }
> >   => "alice"
> >
> > How could I avoid the usage of "eval" to un-escape the string?
>
> s.gsub! /%(\d+)/ do |match|
>    $1.to_i(16).chr
> end
> puts s
>
> You might also consider supporting escaped % literals.

It fails since it should be:

  s.gsub! /%(\d\d)/ do |match|
    $1.to_i(16).chr
  end

Without this change it would fail when matching:

  "%61123"


But fixing it then it works well, thanks a lot :)


-- 
Iñaki Baz Castillo