Comment by kaiuhl

Comment by kaiuhl 17 hours ago

0 replies

Blocks are actually instances of the Proc class. There are helper methods to handle blocks passed to methods in a lightweight manner but you can also accept the block as a method argument, e.g.,

  class Integer
    def times(&blk)
      i = 0
      while i < self
        blk.call(i)
        i += 1
      end
    end
  end