Sha256: 7cfd19172b85b631c94a6c30f9fc416af639b4cc860b61ab5d6bc2d3cd5b0535

Contents?: true

Size: 858 Bytes

Versions: 3

Compression:

Stored size: 858 Bytes

Contents

module PryMoves::Helpers

  extend self

  # @return [String] Signature for the method object in Class#method format.
  def method_signature_with_owner(binding)
    meth = binding.eval('__method__')
    meth_obj = meth ? Pry::Method.from_binding(binding) : nil
    if !meth_obj
      ""
    elsif meth_obj.undefined?
      "#{meth_obj.name_with_owner}(UNKNOWN) (undefined method)"
    else
      args = meth_obj.parameters.inject([]) do |arr, (type, name)|
        name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
        arr << case type
                 when :req   then name.to_s
                 when :opt   then "#{name}=?"
                 when :rest  then "*#{name}"
                 when :block then "&#{name}"
                 else '?'
               end
      end
      "#{meth_obj.name_with_owner}(#{args.join(', ')})"
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pry-moves-0.1.4 lib/pry-moves/helpers.rb
pry-moves-0.1.3 lib/pry-moves/helpers.rb
pry-moves-0.1.2 lib/pry-moves/helpers.rb