diff --git a/guide/english/ruby/ruby-hash/index.md b/guide/english/ruby/ruby-hash/index.md index 78dd64729c..1bebbaf783 100644 --- a/guide/english/ruby/ruby-hash/index.md +++ b/guide/english/ruby/ruby-hash/index.md @@ -34,10 +34,19 @@ You can check how many elements a hash has with the `length` method: my_hash.length # 2 ``` +You can iterate through a hash using the `.each` method: + +```ruby +my_hash = {:key1 => 100, :key2 => 200, :key3 => 300} +my_hash.each { |key, value| puts "#{key} is #{value}" } #=> key1 is 100 + #=> key2 is 200 + #=> key3 is 300 +``` + You can also create integers as hash key but the syntax is different from the usual one ```ruby my_hash = {1: "value"} # will raise an exception my_hash = {1 => "value"} # will create hash with corresponding key value pair -``` \ No newline at end of file +```