Sha256: 87c4e7681af3aabc3f199f558eae6d9a7bc92c8ecdf3f89d657160c95fd24c51

Contents?: true

Size: 738 Bytes

Versions: 9

Compression:

Stored size: 738 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 < Caster
      master_caster!

      cast_with(NilClass) { 'nil' }
      cast_with(Symbol) { |value| ":#{value}" }
      cast_with(String, :to_json)
      cast_with(Object, :to_s)

      # 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)
        cast(value, value.class)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sinclair-2.1.1 lib/sinclair/method_definition/stringifier.rb
sinclair-2.1.0 lib/sinclair/method_definition/stringifier.rb
sinclair-2.0.1 lib/sinclair/method_definition/stringifier.rb
sinclair-2.0.0 lib/sinclair/method_definition/stringifier.rb
sinclair-1.16.3 lib/sinclair/method_definition/stringifier.rb
sinclair-1.16.2 lib/sinclair/method_definition/stringifier.rb
sinclair-1.16.1 lib/sinclair/method_definition/stringifier.rb
sinclair-1.16.0 lib/sinclair/method_definition/stringifier.rb
sinclair-1.15.0 lib/sinclair/method_definition/stringifier.rb