-
-
Save adamakhtar/3356862 to your computer and use it in GitHub Desktop.
Allocate : Create an object but avoid initialization.
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
#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