Example
books = %w{book1 book2 book3 book4}
books.each do |name| print "Book name :: #{name}\n" end
books.each do |name| print "Book name :: #{name}\n" end
In this example code between do and end is Blocks. what it does is that iterates an array using the each method and passes in each element(i.e name) to the code block
No comments:
Post a Comment