65件ヒット
[1-65件を表示]
(0.039秒)
キーワード
- << (6)
- >> (6)
- curry (20)
- parameters (11)
-
source
_ location (11) -
to
_ proc (11)
検索結果
先頭5件
-
Method
# to _ proc -> Proc (6234.0) -
self を call する Proc オブジェクトを生成して返します。
...self を call する Proc オブジェクトを生成して返します。
//emlist[例][ruby]{
class Foo
def foo
"foo"
end
end
m = Foo.new.method(:foo) # => #<Method: Foo#foo>
pr = m.to_proc # => #<Proc:0x007f874d026008 (lambda)>
pr.call # => "foo"
//}... -
Method
# curry -> Proc (224.0) -
self を元にカリー化した Proc を返します。
...した Proc を返します。
カリー化した Proc はいくつかの引数をとります。十分な数の引数が与
えられると、元の Proc に引数を渡し て実行し、結果を返します。引数
の個数が足りないときは、部分適用したカリー化 Proc を返......[a, b, c]
end
proc = self.method(:foo).curry
proc2 = proc.call(1, 2) #=> #<Proc>
proc2.call(3) #=> [1,2,3]
def 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... -
Method
# curry(arity) -> Proc (224.0) -
self を元にカリー化した Proc を返します。
...した Proc を返します。
カリー化した Proc はいくつかの引数をとります。十分な数の引数が与
えられると、元の Proc に引数を渡し て実行し、結果を返します。引数
の個数が足りないときは、部分適用したカリー化 Proc を返......[a, b, c]
end
proc = self.method(:foo).curry
proc2 = proc.call(1, 2) #=> #<Proc>
proc2.call(3) #=> [1,2,3]
def 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... -
Method
# <<(callable) -> Proc (151.0) -
self と引数を合成した Proc を返します。
...成した Proc を返します。
戻り値の Proc は可変長の引数を受け取ります。
戻り値の Proc を呼び出すと、まず受け取った引数を callable に渡して呼び出し、
その戻り値を self に渡して呼び出した結果を返します。
Method#>> とは......の順序が逆になります。
@param callable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。
//emlist[例][ruby]{
def f(x)
x * x
end
def g(x)
x + x
end
# (3 + 3) * (3 + 3)
p (method(:f) << method(:g)).call(3) # => 36
//}
//emlist[call を定義......uby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end
File.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT
pipeline = method(:pp) << WordScanner << File.method(:read)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}
@see Proc#<<, Proc#>>... -
Method
# >>(callable) -> Proc (151.0) -
self と引数を合成した Proc を返します。
...成した Proc を返します。
戻り値の Proc は可変長の引数を受け取ります。
戻り値の Proc を呼び出すと、まず受け取った引数を self に渡して呼び出し、
その戻り値を callable に渡して呼び出した結果を返します。
Method#<< とは......の順序が逆になります。
@param callable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。
//emlist[例][ruby]{
def f(x)
x * x
end
def g(x)
x + x
end
# (3 * 3) + (3 * 3)
p (method(:f) >> method(:g)).call(3) # => 18
//}
//emlist[call を定義......uby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end
File.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT
pipeline = File.method(:read) >> WordScanner >> method(:pp)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}
@see Proc#<<, Proc#>>... -
Method
# parameters -> [object] (10.0) -
Method オブジェクトの引数の情報を返します。
...Method オブジェクトの引数の情報を返します。
Method オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に応じた以下のような Symbol と、仮引数の名......t[例][ruby]{
m = Class.new{define_method(:m){|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}}.instance_method(:m)
m.parameters #=> x], [:opt, :y], [:rest, :other], [:keyreq, :k_x], [:key, :k_y], [:keyrest, :k_other], [:block, :b
File.method(:symlink).parameters #=> req
//}
@see Proc#parameters......st[例][ruby]{
m = Class.new{define_method(:m){|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}}.instance_method(:m)
m.parameters #=> x], [:opt, :y], [:rest, :other], [:keyreq, :k_x], [:key, :k_y], [:keyrest, :k_other], [:block, :b
File.method(:symlink).parameters #=> req
//}
@see Proc#parameters... -
Method
# source _ location -> [String , Integer] | nil (10.0) -
ソースコードのファイル名と行番号を配列で返します。
...返します。
@see Proc#source_location
//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
def foo; end
end
# ----- end of /tmp/foo.rb ----
require '/tmp/foo'
m = Foo.new.method(:foo) # => #<Method: Foo#foo>
m.source_location # => ["/tmp/foo.rb", 2]
method(:puts).source_location...