each

Each iterates over the items stored in this hash, and yields them into an attached block. This will work differently depending on how many parameters the block has.

.each() { |val| ... }

With a one parameter block, each will yield just each value stored in the hash.

marks = { :brian => 5, :greg => 9, :julia => 5 } // outputs 5, 9 and 5 marks.each() do |mark| console( mark ) end

.each() { |key, val| ... }

With two parameters in the block, it will yield both key and value in turn. Note that the first parameter changes when you add the second one.

marks = {
        :brian => 5,
        :greg => 9,
        :julia => 5
}

// outputs name and mark
marks.each() do |name, mark|
    console( name + " received: " + mark )
end