Sha256: f9269dc679b3e971243542a2fc36cfb2c8742c0cc111d9e9cdd28da709e09569

Contents?: true

Size: 489 Bytes

Versions: 10

Compression:

Stored size: 489 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 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/symbol/generate.rb
facets-2.8.3 lib/core/facets/symbol/generate.rb
facets-2.8.2 lib/core/facets/symbol/generate.rb
facets-2.8.1 lib/core/facets/symbol/generate.rb
facets-2.8.0 lib/core/facets/symbol/generate.rb
facets-2.7.0 lib/core/facets/symbol/generate.rb
facets-2.6.0 lib/core/facets/symbol/generate.rb
facets-2.5.1 lib/core/facets/symbol/generate.rb
facets-2.5.0 lib/core/facets/symbol/generate.rb
facets-2.5.2 lib/core/facets/symbol/generate.rb