Proc/Lambda and Symbol/Strings

I have been quite busy these days to get back to continue with the Rails book. Today am trying to understand Procs and Lambdas & Symbol and Strings. Found a wonderful details by Robert Sosinski

Proc/Lambdas/Blocks/Mehtods From His Notes:

Blocks, Procs, Lambdas, and Methods are an aspect of closures in Ruby.

– We can pass blockes to other methods, unlike attributes blocks doesn’t have a name.

– Proc is kind of block, the subtle difference is: proc has a name (unlike block), thus can be used multiple times easily. And another is: a proc can have multiple callbacks which a block can not.

– Lamda is like anonymous methods. The difference with proc is that unlike proc it checkd the number of arguments passed. Also, a return can not be used in the proc block, but can be used in lambda block.

– Methods are like lambdas. Also like regular methods which can be passed to other methods.

Strings/Symbols From His Notes:

– In ruby symbols are immutable, and strings are mutable.

puts "hello" << " world"  => hello world
puts :hello << :" world"  => hello world *.rb:4: undefined method `<<' for :hello:Symbol (NoMethodError)

– In symbol all memory are same as immutable.

puts :"hello world".object_id => 239518 puts :"hello world".object_id => 239518

– In string all memory are different as mutable.

puts "hello world".object_id => 3102960 puts "hello world".object_id => 3098410