Next | 3.7 Enhancing built-in classes | Prev |
class String def unescapeHTML!() gsub!(/&(.*?);/) { case $1 when /\Aamp\z/i then '&' when /\Aquot\z/i then '"' when /\Agt\z/i then '>' when /\Alt\z/i then '<' when /\A#(\d+)\z/ then Integer($1).chr when /\A#x([0-9a-f]+)\z/i then $1.hex.chr end } self end def unescapeHTML() dup().unescapeHTML! end end p "1<2 && 4>3".unescapeHTML # 1<2 && 4>3
Next | Ruby for Perl programmers | Prev |