Posts tagged ‘ruby blocks’
Example using ruby blocks, lambda and Proc
What really distinguishes ruby from other languages is the syntatic sugar of blocks. For example, blocks really come in handy when iterating thru a collection. The example: (1..10).collect{|i| i*i} => [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] But how does the collect method work? Let’s define an array containing all the prime [...]