るりまサーチ

最速Rubyリファレンスマニュアル検索!
36件ヒット [1-36件を表示] (0.152秒)
トップページ > クエリ:i[x] > クエリ:-[x] > クエリ:>[x] > クエリ:d[x] > クエリ:arity[x]

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method gets
  4. irb/input-method new
  5. matrix -

ライブラリ

クラス

キーワード

検索結果

Method#arity -> Integer (27497.0)

メソッドが受け付ける引数の数を返します。

...

-
(必要とされる引数の数 + 1)

を返します。C 言語レベルで実装されたメソッドが可変長引数を
受け付ける場合、-1 を返します。

//emlist[例][ruby]{
class C
d
ef u; end
d
ef v(a); end
d
ef w(*a); end
d
ef x(a,...
...end
d
ef y(a, b, *c); end
d
ef z(a, b, *c, &d); end
end

c = C.new
p c.method(:u).arity #=> 0
p c.method(:v).arity #=> 1
p c.method(:w).arity #=> -1
p c.method(:x).arity #=> 2
p c.method(:y).arity #=> -3
p c.method(:z).arity #=> -3

s = "xyz"
s.method(:size).arity...
...#=> 0
s.method(:replace).arity #=> 1
s.method(:squeeze).arity #=> -1
s.method(:count).arity #=> -1
//}...

UnboundMethod#arity -> Integer (27497.0)

メソッドが受け付ける引数の数を返します。

...
-
(必要とされる引数の数 + 1)
を返します。C 言語レベルで実装されたメソッドが可変長引数を
受け付ける場合、-1 を返します。

//emlist[例][ruby]{
class C
d
ef one; end
d
ef two(a); end
d
ef three(*a); end
d
ef four(a, b); end
d
ef five(a,...
...end
d
ef six(a, b, *c, &d); end
end

p C.instance_method(:one).arity #=> 0
p C.instance_method(:two).arity #=> 1
p C.instance_method(:three).arity #=> -1
p C.instance_method(:four).arity #=> 2
p C.instance_method(:five).arity #=> -3
p C.instance_method(:six).arity #=> -3


Strin...
...g.instance_method(:size).arity #=> 0
String.instance_method(:replace).arity #=> 1
String.instance_method(:squeeze).arity #=> -1
String.instance_method(:count).arity #=> -1
//}...

Method#curry(arity) -> Proc (3425.0)

self を元にカリー化した Proc を返します。

... arity 引数の個数を指定します。可変長の引数を指定できるメソッドを
カリー化する際には必ず指定する必要があります。

//emlist[例][ruby]{
d
ef foo(a,b,c)
[a, b, c]
end

proc = self.method(:foo).curry
proc2 = proc.call(1, 2) #=>...
...#<Proc>
proc2.call(3) #=> [1,2,3]

d
ef vararg(*args)
args
end

proc = self.method(:vararg).curry(4)
proc2 = proc.call(:x) #=> #<Proc>
proc3 = proc2.call(:y, :z) #=> #<Proc>
proc3.call(:a) #=> [:x, :y, :z, :a]
//}

@see Proc#curry...

NEWS for Ruby 3.0.0 (324.0)

NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...Keyword arguments are now separated from positional arguments.
Code that resulted in deprecation warnings in Ruby 2.7 will now
result in ArgumentError or different behavior. 14183
* Procs accepting a single rest argument and keywords are no longer
subject to autosplatting. This now m...
...vior of Procs
accepting a single rest argument and no keywords.
16166

//emlist[][ruby]{
pr = proc{|*a, **kw| [a, kw]}

pr.call([1])
# 2.7 => [[1], {}]
# 3.0 => [[[1]], {}]

pr.call([1, {a: 1}])
# 2.7 => [[1], {:a=>1}] # and deprecation warning
# 3.0 => a=>1}, {}]
//}

* Arguments forwardi...
...leading arguments.
16378

//emlist{
d
ef method_missing(meth, ...)
send(:"do_#{meth}", ...)
end
//}

* Pattern matching (`case/in`) is no longer experimental. 17260
* One-line pattern matching is redesigned. [EXPERIMENTAL]
* `=>` is added. It can be used like a rightward assign...