官术网_书友最值得收藏!

Argument count

The first key difference is that lambdas count the arguments you pass to them, whereas procs do not. Consider this example:

full_name = lambda { |first, last| first + " " + last}  
p full_name.call("Jordan", "Hudgens")

Running this code will work properly. However, observe it when I pass another argument like this:

p full_name.call("Jordan", "David", "Hudgens") 

The application throws an error saying that we're passing in the wrong number of arguments:

Now, let's see what happens with procs:

full_name = Proc.new{ |first, last| first + " " + last}  
p full_name.call("Jordan", "David", "Hudgens")

If you run this code, you can see that it does not throw an error. It simply looks at the first two arguments and ignores anything after that.

In review, lambdas count the arguments passed to them, whereas procs don't.

主站蜘蛛池模板: 漾濞| 吉木萨尔县| 葵青区| 平罗县| 来安县| 格尔木市| 西乌| 石河子市| 巴塘县| 黑山县| 中超| 额敏县| 新河县| SHOW| 视频| 双流县| 营山县| 韶山市| 乌海市| 馆陶县| 旬阳县| 邛崃市| 岳阳县| 舒兰市| 乌拉特中旗| 巴东县| 阿荣旗| 蓝田县| 德州市| 即墨市| 安徽省| 阳高县| 石阡县| 青冈县| 周至县| 酒泉市| 通榆县| 闵行区| 梧州市| 石嘴山市| 织金县|