Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Proc | lambda?

概要

Proc#lambda? -> bool

詳細

手続きオブジェクトの引数の取扱が厳密であるならば true を返却。

サンプルコード
require 'tbpgr_utils'

def hoge(&b) b.lambda? end
def hige;;end
bulk_puts_eval binding, <<-EOS
lambda {}.lambda?
Proc.new {}.lambda?
proc {}.lambda?
hoge {}
method(:hige).to_proc.lambda?
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

lambda {}.lambda?             # => true
Proc.new {}.lambda?           # => false
proc {}.lambda?               # => false
hoge {}                       # => false
method(:hige).to_proc.lambda? # => true