Sha256: a861866df30de9e607ee3bf1662048a20223fa199d39c8f7d4c8dd8d0bc02066

Contents?: true

Size: 858 Bytes

Versions: 10

Compression:

Stored size: 858 Bytes

Contents

class UnboundMethod

  # Resolves the arguments of the method to have an
  # identical signiture --useful for preserving arity.
  #
  #   class X
  #     def foo(a, b); end
  #     def bar(a, b=1); end
  #   end
  #
  #   foo_method = X.instance_method(:foo)
  #   foo_method.arguments   #=> "a0, a1"
  #
  #   bar_method = X.instance_method(:bar)
  #   bar_method.arguments   #=> "a0, *args"
  #
  # When defaults are used the arguments must end in "*args".
  #
  #   CREDIT: Trans

  def arguments
    ar = arity
    case ar <=> 0
    when 1
      args = []
      ar.times do |i|
        args << "a#{i}"
      end
      args = args.join(", ")
    when 0
      args = ""
    else
      ar = -ar - 1
      args = []
      ar.times do |i|
        args << "a#{i}"
      end
      args << "*args"
      args = args.join(", ")
    end
    return args
  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/unboundmethod/arguments.rb
facets-2.3.0 lib/core/facets/unboundmethod/arguments.rb
facets-2.2.0 lib/core/facets/unboundmethod/arguments.rb
facets-2.2.1 lib/core/facets/unboundmethod/arguments.rb
facets-2.4.1 lib/facets/unboundmethod/arguments.rb
facets-2.4.2 lib/core/facets/unboundmethod/arguments.rb
facets-2.4.3 lib/core/facets/unboundmethod/arguments.rb
facets-2.4.4 lib/core/facets/unboundmethod/arguments.rb
facets-2.4.5 lib/core/facets/unboundmethod/arguments.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/unboundmethod/arguments.rb