ruby 판단 방법 수신 매개 변수 개수

obj#arity
class C
  def one;    end
  def need_block(&block); end
  def two(a); end
  def three(*a);  end
  def four(a, b); end
  def five(a, b, *c);    end
  def six(a, b, *c, &d); end
end

c = C.new
c.method(:one).arity     #=> 0 
c.method(:need_block).arity     #=> 0 
c.method(:two).arity     #=> 1
c.method(:three).arity   #=> -1
c.method(:four).arity    #=> 2
c.method(:five).arity    #=> -3
c.method(:six).arity     #=> -3
das

좋은 웹페이지 즐겨찾기