Last active
August 29, 2015 13:59
-
-
Save mezis/10637428 to your computer and use it in GitHub Desktop.
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 FrozenString | |
module ClassMethods | |
def get(string) | |
@@repository ||= {} | |
@@repository[string.freeze] ||= new(string.freeze) | |
end | |
end | |
extend ClassMethods | |
def initialize(string) | |
@value = string | |
end | |
def to_str | |
@value | |
end | |
alias_method :to_s, :to_str | |
class << self | |
private :new | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The implementation looks good, just missing some tests hehe. I can take a spin to this later on.
Any reason why not just do
def this.get
? Code style ?