Interviewer And Interviewee Guide

Ruby Developer Interview Question:

Tell me what are blocks and procs?

Submitted by: Muhammad
A block is basically Ruby's version of a closure-a block of code that can be wrapped up into a proc (a type of function) that can then be stored in a variable or passed to a method and run when desired. Blocks can syntactically be written as blocks of code between { } or the do and end keywords. The standard way to create a proc is depicted in the code block below.

> my_proc = Proc.new { |arg1| print "#{arg1}! " }
Submitted by: Muhammad

Read Online Ruby Developer Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.