Skip to content

Instantly share code, notes, and snippets.

@mezis
Last active August 29, 2015 13:59
Show Gist options
  • Save mezis/10637428 to your computer and use it in GitHub Desktop.
Save mezis/10637428 to your computer and use it in GitHub Desktop.
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
@pedrocunha
Copy link

The implementation looks good, just missing some tests :trollface: hehe. I can take a spin to this later on.

Any reason why not just do def this.get ? Code style ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment