Sha256: 0f0681c1e7d1ad1c1ebe9cf867e58f261a1657b2f99491bcd3cc61510e4eb6c2

Contents?: true

Size: 772 Bytes

Versions: 16

Compression:

Stored size: 772 Bytes

Contents

# frozen_string_literal: true

class Serega
  module SeregaUtils
    #
    # Utility to get frozen string from symbol in any ruby version
    #
    class SymbolName
      class << self
        #
        # Returns frozen string corresponding to provided symbol
        #
        # @param key [Symbol]
        #
        # @return [String] frozen string corresponding to provided symbol
        #
        def call(key)
          key.is_a?(String) ? key : to_frozen_string(key)
        end

        private

        # :nocov:
        if RUBY_VERSION < "3"
          def to_frozen_string(key)
            key.to_s.freeze
          end
        else
          def to_frozen_string(key)
            key.name
          end
        end
        # :nocov:
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
serega-0.21.0 lib/serega/utils/symbol_name.rb
serega-0.20.1 lib/serega/utils/symbol_name.rb
serega-0.20.0 lib/serega/utils/symbol_name.rb
serega-0.19.0 lib/serega/utils/symbol_name.rb
serega-0.18.0 lib/serega/utils/symbol_name.rb
serega-0.17.0 lib/serega/utils/symbol_name.rb
serega-0.16.0 lib/serega/utils/symbol_name.rb
serega-0.15.0 lib/serega/utils/symbol_name.rb
serega-0.14.0 lib/serega/utils/symbol_name.rb
serega-0.12.0 lib/serega/utils/symbol_name.rb
serega-0.11.2 lib/serega/utils/symbol_name.rb
serega-0.11.1 lib/serega/utils/symbol_name.rb
serega-0.11.0 lib/serega/utils/symbol_name.rb
serega-0.10.0 lib/serega/utils/symbol_name.rb
serega-0.9.0 lib/serega/utils/symbol_name.rb
serega-0.8.3 lib/serega/utils/symbol_name.rb