Sha256: c5be54782abc8ddbf4b2bd5d63422cd64baa8fad8a95e6ecc97f4dfbf59f8b53

Contents?: true

Size: 696 Bytes

Versions: 4

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true

require 'sinclair/core_ext/object'

class Sinclair
  class MethodDefinition
    # @api private
    # @author darthjee
    #
    # Stringgify a value for {StringDefinition}
    class Stringifier
      # Convert a value to a string format
      #
      # The returned string can be evaluated as code, returning the
      # original value
      #
      # @param value [Object] object to be converted
      #
      # @return [String]
      def self.value_string(value)
        return 'nil' if value.nil?
        return ":#{value}" if value.is_a?(Symbol)

        return value.to_s if value.is_any?(Class, Hash, Array)

        value.to_json
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sinclair-1.14.2 lib/sinclair/method_definition/stringifier.rb
sinclair-1.14.1 lib/sinclair/method_definition/stringifier.rb
sinclair-1.14.0 lib/sinclair/method_definition/stringifier.rb
sinclair-1.13.0 lib/sinclair/method_definition/stringifier.rb