Sha256: 1f2e622547ba5fdb7a4a324a191aae08d36f489dafbb6e7e7cdd6fc359811a6a

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# typed: strict
# frozen_string_literal: true

module Spoom
  module Deadcode
    # An abstraction to simplify handling of Prism::CallNode nodes.
    class Send < T::Struct
      extend T::Sig

      const :node, Prism::CallNode
      const :name, String
      const :recv, T.nilable(Prism::Node), default: nil
      const :args, T::Array[Prism::Node], default: []
      const :block, T.nilable(Prism::Node), default: nil

      sig do
        type_parameters(:T)
          .params(arg_type: T::Class[T.type_parameter(:T)], block: T.proc.params(arg: T.type_parameter(:T)).void)
          .void
      end
      def each_arg(arg_type, &block)
        args.each do |arg|
          yield(T.unsafe(arg)) if arg.is_a?(arg_type)
        end
      end

      sig { params(block: T.proc.params(key: Prism::Node, value: T.nilable(Prism::Node)).void).void }
      def each_arg_assoc(&block)
        args.each do |arg|
          next unless arg.is_a?(Prism::KeywordHashNode) || arg.is_a?(Prism::HashNode)

          arg.elements.each do |assoc|
            yield(assoc.key, assoc.value) if assoc.is_a?(Prism::AssocNode)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spoom-1.3.2 lib/spoom/deadcode/send.rb
spoom-1.3.1 lib/spoom/deadcode/send.rb
spoom-1.3.0 lib/spoom/deadcode/send.rb