ミームの死骸を待ちながら

We are built as gene machines and cultured as meme machines, but we have the power to turn against our creators. We, alone on earth, can rebel against the tyranny of the selfish replicators. - Richard Dawkins "Selfish Gene"

We are built as gene machines and cultured as meme machines, but we have the power to turn against our creators.
We, alone on earth, can rebel against the tyranny of the selfish replicators.
- Richard Dawkins "Selfish Gene"

"Ruby Recipe 061"文字列の一部を破壊的に削除する


「ある文字列を正規表現で指定して、""で置換する」という考え方。sub!あるいはgsub!を使う。

  • sub系は
    • 第一引数で正規表現「/hogehoge/」あるいは特定の文字列「"hogehoge"」
    • 第二引数で置換先の文字列

指定した位置に文字列を挿入する方法も。

str.sub!(/\A.{3}/m){|s| s + "insert"}