るりまサーチ

最速Rubyリファレンスマニュアル検索!
59件ヒット [1-59件を表示] (0.107秒)

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. rsa p
  5. dsa p

ライブラリ

キーワード

検索結果

Method#to_proc -> Proc (6224.0)

self を call する Proc オブジェクトを生成して返します。

...self を call する Proc オブジェクトを生成して返します。

//emlist[例][ruby]{
class Foo
def foo
"foo"
end
end

m = Foo.new.method(:foo) # => #<Method: Foo#foo>
p
r = m.to_proc # => #<Proc:0x007f874d026008 (lambda)>
p
r.call # => "foo"
//}...

Method#super_method -> Method | nil (6114.0)

self 内で super を実行した際に実行されるメソッドを Method オブジェ クトにして返します。

...uper を実行した際に実行されるメソッドを Method オブジェ
クトにして返します。

@see UnboundMethod#super_method

//emlist[例][ruby]{
class Super
def foo
"superclass method"
end
end

class Sub < Super
def foo
"subclass method"
end
end

m = Sub.new.method(...
...:foo) # => #<Method: Sub#foo>
m.call # => "subclass method"
m.super_method # => #<Method: Super#foo>
m.super_method.call # => "superclass method"
//}...

Method#<<(callable) -> Proc (238.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

p
ipeline = method(:pp) << WordScanner << File.method(:read)
p
ipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Proc#<<, Proc#>>...

Method#>>(callable) -> Proc (238.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

p
ipeline = File.method(:read) >> WordScanner >> method(:pp)
p
ipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Proc#<<, Proc#>>...

Method#curry -> Proc (132.0)

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

...化した Proc を返します。

カリー化した Proc はいくつかの引数をとります。十分な数の引数が与
えられると、元の Proc に引数を渡し て実行し、結果を返します。引数
の個数が足りないときは、部分適用したカリー化 Proc を...
...

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

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

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

def vararg(*args)
args
end

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

@see Proc#curry...

絞り込み条件を変える

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

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

...化した Proc を返します。

カリー化した Proc はいくつかの引数をとります。十分な数の引数が与
えられると、元の Proc に引数を渡し て実行し、結果を返します。引数
の個数が足りないときは、部分適用したカリー化 Proc を...
...

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

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

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

def vararg(*args)
args
end

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

@see Proc#curry...