Skip to content

Instantly share code, notes, and snippets.

@jonnyzheng
Created March 8, 2012 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonnyzheng/1998921 to your computer and use it in GitHub Desktop.
Save jonnyzheng/1998921 to your computer and use it in GitHub Desktop.
Proc and lambda
class Testclass
def mytest(&block)
result = block.call
return result * 2
end
end
def myclient
myproc = Proc.new{return 10}
test = Testclass.new
puts test.mytest(&myproc)
# 123 would never be print
puts '123'
end
# will print 10
puts myclient
class Testclass
def mytest(&block)
result = block.call
return result * 2
end
end
myproc = Proc.new{return 10}
test = Testclass.new
# will print: `block in <main>': unexpected return (LocalJumpError)
puts test.mytest(&myproc)
class Testclass
def mytest(&block)
result = block.call
return result * 2
end
end
myproc = lambda{return 10}
test = Testclass.new
# will print: 20
puts test.mytest(&myproc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment