Sha256: 00c47458dbc82ef6ad80160cdc9b47e0d9ae09042bddc528fa3125651c05a065

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

module Unparser
  class Emitter
    class Literal

      # Base class for primitive emitters
      class Primitive < self

        children :value

      private

        # Emitter for primitives based on Object#inspect
        class Inspect < self

          handle :sym, :str

        private

          # Dispatch value
          #
          # @return [undefined]
          #
          # @api private
          #
          def dispatch
            write(value.inspect)
          end

        end # Inspect

        # Emiter for numeric literals
        class Numeric < self

          handle :int, :float

        private

          # Dispatch value
          #
          # @return [undefined]
          #
          # @api private
          #
          def dispatch
            conditional_parentheses(parent.kind_of?(Emitter::Send) && value < 0) do
              write(value.inspect)
            end
          end

        end # Numeric
      end # Primitive
    end # Literal
  end # Emitter
end # Unparser

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
unparser-0.1.12 lib/unparser/emitter/literal/primitive.rb
unparser-0.1.11 lib/unparser/emitter/literal/primitive.rb
unparser-0.1.10 lib/unparser/emitter/literal/primitive.rb
unparser-0.1.9 lib/unparser/emitter/literal/primitive.rb
unparser-0.1.8 lib/unparser/emitter/literal/primitive.rb