Skip to content

Instantly share code, notes, and snippets.

@adamakhtar
Created August 15, 2012 06:07
Show Gist options
  • Save adamakhtar/3356862 to your computer and use it in GitHub Desktop.
Save adamakhtar/3356862 to your computer and use it in GitHub Desktop.
Allocate : Create an object but avoid initialization.
#allocate()
#Allocates space for a new object of class’s class and does not call initialize on the new instance. The returned object #must be an instance of class.
klass = Class.new do
def initialize(*args)
@initialized = true
end
def initialized?
@initialized || false
end
end
klass.allocate.initialized? #=> false
#useful for testing e.g. in Jekyll
def test_process
p = Post.allocate
p.process("2008-10-19-foo-bar.textile")
assert_equal Time.parse("2008-10-19"), p.date
assert_equal "foo-bar", p.slug
assert_equal ".textile", p.ext
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment