# Proc & block

e\$B1J0fe([email protected]\$BCNG=!%6e9)Bg\$G\$9!%e(B

e\$B8=:_\$Ne(B Proc
e\$B%*%V%8%’%/%H\$O%V%m%C%/\$r<u\$1<h\$k\$3\$H\$,\$G\$-\$^\$;\$s\$,!\$e(B
e\$B\$3\$l\$r<u\$1<h\$k\$3\$H\$,\$G\$-\$k\$h\$&\$K\$9\$k\$3\$H\$OFq\$7\$\$\$G\$7\$g\$&\$+!%e(B

## x = proc{|m, *args| [block_given?, m.call(*args)] } x.call(method(:foo), 1,2,3){p 111} #=> [false, [1, 2, 3, false]]

e\$B\$G\$O%V%m%C%/\$rM?\$(\$k\$3\$H\$,\$G\$-\$^\$;\$s!%e(B

## def bar(m, *args, &blk) [block_given?, m.call(*args, &blk)] end x = method(:bar) x.call(method(:foo), 1,2,3){p 111} #=> [true, [1, 2, 3, true]]

e\$B\$H\$\$\$&\$h\$&\$K%a%=%C%I\$rDj5A\$9\$kI,MW\$,\$"\$j\$^\$9!%e(B

## x = proc{|m, *args, &blk| [block_given?, m.call(*args, &blk)] } x.call(method(:foo), 1,2,3){p 111} #=> [true, [1, 2, 3, true]]

e\$B\$H\$G\$-\$F!\$M>7W\$J%a%=%C%IDj5A\$r\$7\$J\$/\$F:Q\$`\$N\$G\$9\$,!%!%!%e(B

## [email protected]\$7\$=\$N>l9g!\$8=>u\$Ne(B

def baz
proc{|*args| [block_given?, *args]}
end

baz.call(1,2,3) #=> [false, 1, 2, 3]
baz{p 111}.call(1,2,3) #=> [true, 1, 2, 3]

e\$BKNIt\$G\$9!#e(B

Hidetoshi NAGAI wrote:

e\$B1J0fe([email protected]\$BCNG=!%6e9)Bg\$G\$9!%e(B

e\$B8=:_\$Ne(B Proc e\$B%*%V%8%’%/%H\$O%V%m%C%/\$r<u\$1<h\$k\$3\$H\$,\$G\$-\$^\$;\$s\$,!\$e(B

1.9e\$B\$G\$O\$G\$-\$^\$9\$h!#e(B
1.8e\$B\$KF3F~\$9\$k\$K\$O\$A\$g\$C\$HBg\$-\$9\$.\$kJQ99\$N\$h\$&\$K;W\$\$\$^\$9\$,!#e(B

e\$B1J0fe([email protected]\$BCNG=!%6e9)Bg\$G\$9!%e(B

From: “URABE Shyouhei aka. mput” [email protected]
Subject: [ruby-dev:28499] Re: proc & block
Date: Mon, 3 Apr 2006 19:00:15 +0900
Message-ID: [email protected]

e\$B8=:_\$Ne(B Proc e\$B%*%V%8%’%/%H\$O%V%m%C%/\$r<u\$1<h\$k\$3\$H\$,\$G\$-\$^\$;\$s\$,!\$e(B

1.9e\$B\$G\$O\$G\$-\$^\$9\$h!#e(B

e\$B\$"!\$e(B1.9 e\$B\$G\$O\$G\$-\$?\$s\$G\$9\$M!%e(B(^_^;
e\$B\$-\$A\$s\$H3NG’\$7\$F\$\$\$^\$;\$s\$G\$7\$?!%\$4\$a\$s\$J\$5\$\$!%e(B

1.8e\$B\$KF3F~\$9\$k\$K\$O\$A\$g\$C\$HBg\$-\$9\$.\$kJQ99\$N\$h\$&\$K;W\$\$\$^\$9\$,!#e(B

1.9 e\$B\$,\$I\$N\$h\$&\$J;EMM\$K\$J\$C\$F\$\$\$k\$+\$O8e\$G3NG’\$7\$h\$&\$H;W\$\$\$^\$9\$,!\$e(B
e\$B\$d\$O\$jBg\$-\$9\$.\$kJQ99\$G\$7\$g\$&\$+!%e(B
e\$B%"%C%Q!<%3%s%Q%A\$K\$O\$G\$-\$=\$&\$J5\$\$,\$9\$k\$N\$G\$9\$,!%!%!%e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.