Basic Ruby
jimibue (1)

Ruby Block

Blocks are anonymous functions (i.e. not named) that are passed into methods.

Examples

  # If a block is a single line use {}
	5.times { |x| puts x}

  # If a block requires multiple lines enclose in do end
	5.upto(10) do |x|
    if x.odd?
        puts 'odd'
      end
      puts 'even' 
	end
You are viewing a single comment. View All