Method: RDF::URI.intern

Defined in:
lib/rdf/model/uri.rb

.intern(str, *args, **options) ⇒ RDF::URI

Returns an interned RDF::URI instance based on the given uri string.

The maximum number of cached interned URI references is given by the CACHE_SIZE constant. This value is unlimited by default, in which case an interned URI object will be purged only when the last strong reference to it is garbage collected (i.e., when its finalizer runs).

Excepting special memory-limited circumstances, it should always be safe and preferred to construct new URI references using RDF::URI.intern instead of RDF::URI.new, since if an interned object can't be returned for some reason, this method will fall back to returning a freshly-allocated one.

(see #initialize)

Returns:

  • (RDF::URI)

    an immutable, frozen URI object



166
167
168
# File 'lib/rdf/model/uri.rb', line 166

def self.intern(str, *args, **options)
  (cache[(str = str.to_s).to_sym] ||= self.new(str.to_s, *args, **options)).freeze
end