タグ

関連タグで絞り込む (1)

タグの絞り込みを解除

rubytに関するtuto0621のブックマーク (1)

  • Tenderlove Making - Weird stuff with hashes

    Ok, so this isn’t really weird stuff, I don’t think. But maybe people don’t know about it so I thought I would post. Hashes dup string keys When you assign a string key to a hash, the hash copies the string and freezes it. Here is an example: >> x = 'string' => "string" >> y = {} => {} >> y[x] = :value => :value >> { x => y.keys.first } => {"string"=>"string"} >> { x.object_id => y.keys.first.obje

    tuto0621
    tuto0621 2015/02/14
    Hashに渡した文字列は自動でコピーされてfreezerされる理由。速くするためには事前にfreezeした文字列を渡すとよい。'benchmark/ips' 便利そうだ。
  • 1