Hi,

Daniel DeLorme wrote:
>> == String#gsub(regexp, hash)
>> Proposal to allow the following syntax:
>>    String#gsub(regexp, {"ä"=>"\u00C4", ..})
>> -> accepted
> 
> This is very nice; I've often had to use a pattern roughly like
>   string.gsub(/#{hash.keys.join("|")}/){ h[$&] }
> But shouldn't the syntax be more like this?
>   String#gsub({"ä"=>"\u00C4", ..})

/ä|å|.../ may be slower than /&\w+;/.  String#gsub seems 
performance conscious.

> I can't really see a use case for keeping the regex separate from the 
> hash... what happens in a case like this?
>   "abc".gsub(/a/,{})
> "a" gets deleted?

You can use default value of hash.

s = "<foo>aä & ∞</foo>"
TABLE_HTMLREF = Hash.new{|hash, key| key}
TABLE_HTMLREF.update(
  '&lt;' => '<',
  '&gt;' => '>',
  '&amp;' => '&',
  '&auml;' => "\u00C4",
  '&infin;' => "\u221E"
)
s.gsub(/&\w+;/, TABLE_HTMLREF)

>> == String#getbyte, String#setbyte
>> -> accepted
> 
> Great! Will this method take/return integers or 1-byte-long strings?

Integer.  This feature is already implemented, so you can try following.

s = "ABCDE"
s.getbyte(0) #=> 65
s.setbyte(0, 97)
s #=> "aBCDE"

-- 
NARUSE, Yui  <naruse / airemix.com>
DBDB A476 FDBD 9450 02CD 0EFC BCE3 C388 472E C1EA