Sha256: 39169114b76a9712d5495ea53bc0344f9b6b2476a0b9dad0a49276855151a125

Contents?: true

Size: 495 Bytes

Versions: 10

Compression:

Stored size: 495 Bytes

Contents

class Symbol

  # Generate a unique symbol.
  #
  #   Symbol.generate  #=> :"-1"
  #
  # If +key+ is given the new symbol will be prefixed with it.
  #
  #   Symbol.generate(:foo)  #=> :"foo-1"
  #
  # TODO: Is the generated symbol format acceptable?
  #
  # CREDIT: Trans

  def self.generate(key=nil)
    key = key.to_sym if key
    @symbol_generate_counter ||= {}
    @symbol_generate_counter[key] ||= 0
    num = @symbol_generate_counter[key] += 1
    ("#{key}-%X" % num).to_sym
  end

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/symbol/generate.rb
facets-3.1.0 lib/core/facets/symbol/generate.rb
facets-3.0.0 lib/core/facets/symbol/generate.rb
facets-2.9.3 lib/core/facets/symbol/generate.rb
facets-2.9.2 src/core/facets/symbol/generate.rb
facets-2.9.2 lib/core/facets/symbol/generate.rb
facets-2.9.1 lib/core/facets/symbol/generate.rb
facets-2.9.0 lib/core/facets/symbol/generate.rb
facets-2.9.0.pre.2 lib/core/facets/symbol/generate.rb
facets-2.9.0.pre.1 lib/core/facets/symbol/generate.rb