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?



Explain ampersand parameter (&block) in Ruby?..

Answer / 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

More Ruby Interview Questions

Can method names be capitalized?

1 Answers  


Overview of ruby programming language?

1 Answers  


How ruby looks up a method to invoke?

1 Answers  


Explain the use of ensure statement in Ruby?

1 Answers  


Tell me how you can create a controller for subject?

1 Answers  


What are the case statement in ruby?

1 Answers  


What is the difference between nil and false in ruby?

1 Answers  


Explain the use of retry statement in ruby?

1 Answers  


What are the operators available in ruby?

1 Answers  


Explain how can we define ruby regular expressions?

1 Answers  


Write the command to get installed Ruby version in your system?

1 Answers  


Explain some differences between ruby and python.

1 Answers  


Categories