Sha256: 720188fe0e849a03fbf0472c57760c0f0c94e0a605377fdb3c56ea2c7d9baae2

Contents?: true

Size: 856 Bytes

Versions: 20

Compression:

Stored size: 856 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

20 entries across 19 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/unboundmethod/arguments.rb
facets-3.1.0 lib/core/facets/unboundmethod/arguments.rb
facets-3.0.0 lib/core/facets/unboundmethod/arguments.rb
facets-2.9.3 lib/core/facets/unboundmethod/arguments.rb
facets-2.9.2 src/core/facets/unboundmethod/arguments.rb
facets-2.9.2 lib/core/facets/unboundmethod/arguments.rb
facets-2.9.1 lib/core/facets/unboundmethod/arguments.rb
facets-2.9.0 lib/core/facets/unboundmethod/arguments.rb
facets-2.9.0.pre.2 lib/core/facets/unboundmethod/arguments.rb
facets-2.9.0.pre.1 lib/core/facets/unboundmethod/arguments.rb
facets-2.8.4 lib/core/facets/unboundmethod/arguments.rb
facets-2.8.3 lib/core/facets/unboundmethod/arguments.rb
facets-2.8.2 lib/core/facets/unboundmethod/arguments.rb
facets-2.8.1 lib/core/facets/unboundmethod/arguments.rb
facets-2.8.0 lib/core/facets/unboundmethod/arguments.rb
facets-2.7.0 lib/core/facets/unboundmethod/arguments.rb
facets-2.6.0 lib/core/facets/unboundmethod/arguments.rb
facets-2.5.1 lib/core/facets/unboundmethod/arguments.rb
facets-2.5.0 lib/core/facets/unboundmethod/arguments.rb
facets-2.5.2 lib/core/facets/unboundmethod/arguments.rb