Sha256: 95e2fce2a855738a764096fdcf1053aa5a360119691fbf0e903392af20629f75

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

module Unparser
  class Emitter
    # Emitter for def node
    class Def < self

    private

      # Emit name
      #
      # @return [undefined]
      #
      # @api private
      #
      abstract_method :emit_name
      private :emit_name

      # Return body node
      #
      # @return [Parser::AST::Node]
      #
      # @api private
      #
      abstract_method :body
      private :body

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        write(K_DEF, WS)
        emit_name
        emit_arguments
        emit_body
        k_end
      end

      # Emit arguments
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_arguments
        return if arguments.children.empty?
        parentheses do
          visit(arguments)
        end
      end

      # Instance def emitter
      class Instance < self

        handle :def

        children :name, :arguments, :body

      private

        # Emit name
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_name
          write(name.to_s)
        end

      end # Instance

      # Emitter for defines on singleton
      class Singleton < self

        handle :defs

        children :subject, :name, :arguments, :body

      private

        # Return mame
        #
        # @return [String]
        #
        # @api private
        #
        def emit_name
          visit(subject)
          write(T_DOT, name.to_s)
        end

      end # Singleton
    end # Def
  end # Emitter
end # Unparser

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
unparser-0.1.0 lib/unparser/emitter/def.rb
unparser-0.0.18 lib/unparser/emitter/def.rb
unparser-0.0.16 lib/unparser/emitter/def.rb
unparser-0.0.15 lib/unparser/emitter/def.rb
unparser-0.0.14 lib/unparser/emitter/def.rb
unparser-0.0.13 lib/unparser/emitter/def.rb
unparser-0.0.12 lib/unparser/emitter/def.rb
unparser-0.0.11 lib/unparser/emitter/def.rb
unparser-0.0.10 lib/unparser/emitter/def.rb
unparser-0.0.8 lib/unparser/emitter/def.rb
unparser-0.0.7 lib/unparser/emitter/def.rb
unparser-0.0.6 lib/unparser/emitter/def.rb
unparser-0.0.5 lib/unparser/emitter/def.rb
unparser-0.0.4 lib/unparser/emitter/def.rb
unparser-0.0.3 lib/unparser/emitter/def.rb