Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Explain ampersand parameter (&block) in Ruby?

Answer Posted / Ankur Bhardwaj

The '&block;' parameter in Ruby is a shorthand syntax for defining block methods. It allows you to define a method that can be passed as a block of code to other methods. The '&' symbol is used to reference this block in the method definition.nFor example:nndef sum(&block)n block.call(1) { |num| num + 2 } # This calls the block with argument 1 and expects it to return a number that will be added by 2.nendnsum do |number|n number * numbernend

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me the role of modules and mixins in ruby?

2