Skip to content

Instantly share code, notes, and snippets.

@mezis mezis/frozen_string.rb
Last active Aug 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

pedrocunha commented Apr 14, 2014

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
You can’t perform that action at this time.