Created
June 26, 2013 22:43
-
-
Save jgaskins/5872405 to your computer and use it in GitHub Desktop.
Fix initialize method-name typos once and for all.
This file contains hidden or 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
class Class | |
# Important: keep 'initialize' at the end of this array | |
COMMON_INIT_MISSPELLINGS = %w(intitialize intialize initialise initialize) # etc... | |
def new(*args) | |
obj = allocate | |
obj.send COMMON_INIT_MISSPELLINGS.find { |m| obj.respond_to? m }, *args | |
obj | |
end | |
end | |
class Foo | |
def intialize | |
@bar = 'baz' | |
end | |
end | |
p Foo.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment