Created
April 17, 2014 20:54
-
-
Save MrJoy/11010959 to your computer and use it in GitHub Desktop.
Make the constructor private in Ruby.
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
class Example | |
class << self | |
def my_alternative_constructor | |
# From here you can call .new, and do fun things like say, call .freeze before returning the instance. | |
return Example.new.freeze | |
end | |
protected | |
alias_method :private_new, :new | |
def new(*args) | |
private_new(*args) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment