Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
we don't need to do this just switch behaviour based on type
- Loading branch information
1 parent
ffbec4f
commit 26f21ad
Showing
2 changed files
with
10 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,14 @@ def self.escape_punctuation(string) | |
string.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang') | ||
end | ||
|
||
def self.memoist_eval(klass, *args, &block) | ||
if klass.respond_to?(:class_eval) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
matthewrudy
via email
Author
Owner
|
||
klass.class_eval(*args, &block) | ||
else | ||
klass.singleton_class.class_eval(*args, &block) | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def self.included(base) | ||
base.class_eval do | ||
|
@@ -91,7 +99,7 @@ def memoize(*method_names) | |
unmemoized_method = Memoist.unmemoized_method_for(method_name, identifier) | ||
memoized_ivar = Memoist.memoized_ivar_for(method_name, identifier) | ||
|
||
class_eval do | ||
Memoist.memoist_eval(self) do | ||
include InstanceMethods | ||
|
||
if method_defined?(unmemoized_method) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 26f21ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool.
You could even cut out a bit of duplication with this: