Skip to content

Instantly share code, notes, and snippets.

Sam Stephenson sstephenson

View GitHub Profile
@mislav
mislav / procs-vs-lambda.md
Last active Mar 19, 2019
Jim Weirich on the differences between procs and lambdas in Ruby
View procs-vs-lambda.md

Jim Weirich:

This is how I explain it… Ruby has Procs and Lambdas. Procs are created with Proc.new { }, lambdas are created with lambda {} and ->() {}.

In Ruby 1.8, proc {} creates lambda, and Ruby 1.9 it creates procs (don't ask).

Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.

This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.

View rbenv.bash
_commands()
{
local cur commands
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
commands="exec prefix rehash set-default set-local version versions\
whence which"
COMPREPLY=( $( compgen -W "${commands}" -- ${cur} ) )
}
You can’t perform that action at this time.