Memoize methods that depend on instance state automatically
dkubb opened this issue · comments
An immutable object's state never changes, so the #hash
, #inspect
and #to_s
methods are idempotent. These methods should be memoized by default.
I like this change.
We have to communicate methods need to be present / changed before Adamantium
is included. Especially in conjunction with Equalizer
.
Correct:
class Foo
include Adamantium, Equalizer.new(:foo)
end
Incorrect:
class Foo
include Equalizer.new(:foo), Adamantium
end
Module#include
does include modules in reverse order.
@mbj sure, the first thing we could do show examples using include
on separate lines, then it's more clear the ordering of things. We can have an "advanced" section showing this one-liner, which includes Equalizer first then Adamantium.
I just remember a chat conversation in #jruby
, we improved performance on rack hashes with using separate String subclasses for keys that freezed contents and cachesObject#hash
I lost the gist the guy created but we had around 20% speedup.