Learn to Code via Tutorials on Repl.it!

← Back to all posts
Basic Ruby
jimibue (1)

Ruby Block

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


  # 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'
      puts 'even' 
sugarfi (489)

Good tutorial, but you should add some sort of introduction and possibly add other features of the language, like variables or functions.