New proc syntax in 1.9

BEGIN {
  puts "Ruby Version : #{RUBY_VERSION}"
}

succ = ->(x=0) { x + 1 }
p succ.call
p succ.call(2)

successor = Proc.new {|x=0| x + 1}
p successor.call
p successor.call(10)

Output

Ruby Version : 1.9.1
1
3
1
11

But thanks, I will stick with the old syntax!

Monday, January 4, 2010 — 1 note
  1. itsgg posted this