ruby on rails - Using a frozen constant as a hash key? -
i built small api makes few calls have similar payloads, have base payload merge in call-specific elements, so: def foo_call base_payload.merge({"request.id" => request_id}) end def biz_call base_payload.merge({"request.id" => some_other_thing}) end def base_payload { bar: bar, baz: baz, "request.id" => default_id } end my coworker suggested make "request.id" frozen constant, arguing making constant means can freeze means wont allocating new string object on each call, saving bit of memory. this: requestid = "request.id".freeze def foo_call base_payload.merge({requestid => request_id}) end def biz_call base_payload.merge({requestid => some_other_thing}) end def base_payload { bar: bar, baz: baz, requestid => default_id } end i'm little apprehensive, can't quite pin down reason why not (other latent resistance @ having new commit :> ). feel might cause...