Skip to content

Instantly share code, notes, and snippets.

@mbj
Created November 22, 2012 18:03
Show Gist options
  • Save mbj/4132399 to your computer and use it in GitHub Desktop.
Save mbj/4132399 to your computer and use it in GitHub Desktop.
# Scenario when Classes and Modules are duped in memoizers!
class A
include Adamantium::Flat
def foo
:foo
end
memoize :foo
end
class Generator
include Adamantium::Flat
def generate(value)
klass.new(value)
end
def klass
A
end
memoize :klass
end
foo = Generator.new.generate(foo)
p foo.class
p foo.instance_of?(A) # => false!!!
p foo.foo # Blows up as method cannot be bound to instance of cloned class!
#<Class:0x00000001d23c18>
false
/home/mbj/.rvm/gems/ruby-1.9.3-p286/gems/adamantium-0.0.3/lib/adamantium/module_methods.rb:80:in `bind': bind argument must be an instance of A (TypeError)
from /home/mbj/.rvm/gems/ruby-1.9.3-p286/gems/adamantium-0.0.3/lib/adamantium/module_methods.rb:80:in `block (2 levels) in define_memoize_method'
from /home/mbj/.rvm/gems/ruby-1.9.3-p286/gems/adamantium-0.0.3/lib/adamantium/module_methods.rb:79:in `fetch'
from /home/mbj/.rvm/gems/ruby-1.9.3-p286/gems/adamantium-0.0.3/lib/adamantium/module_methods.rb:79:in `block in define_memoize_method'
from blow.rb:30:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment