diff options
author | Levi Bostian <levi.bostian@gmail.com> | 2015-10-12 23:00:09 -0500 |
---|---|---|
committer | Levi Bostian <levi.bostian@gmail.com> | 2015-10-12 23:00:09 -0500 |
commit | 574b7faf50c9ef608a3e9cf1ee88b85c05554a8b (patch) | |
tree | 277a04a7d37ad01ce0fdd1851c83bddaf033aceb /ruby.html.markdown | |
parent | 1dc869a2f3cc43ce95caaf324c55687071295997 (diff) | |
parent | 7b4d529c5e0dd4b62cf91a90ec72fe40ecca86ec (diff) |
Merge pull request #1392 from ghalley/updates
[ruby/en] Add modulus, array.first, array.last, and each_with_index
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r-- | ruby.html.markdown | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown index fe142365..c10255d8 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -12,6 +12,7 @@ contributors: - ["Dzianis Dashkevich", "https://github.com/dskecse"] - ["Levi Bostian", "https://github.com/levibostian"] - ["Rahil Momin", "https://github.com/iamrahil"] + - ["Gabriel Halley", https://github.com/ghalley] --- @@ -39,6 +40,7 @@ You shouldn't either 10 * 2 #=> 20 35 / 5 #=> 7 2**5 #=> 32 +5 % 3 #=> 2 # Arithmetic is just syntactic sugar # for calling a method on an object @@ -160,6 +162,7 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5] # Arrays can be indexed # From the front array[0] #=> 1 +array.first #=> 1 array[12] #=> nil # Like arithmetic, [var] access @@ -170,6 +173,7 @@ array.[] 12 #=> nil # From the end array[-1] #=> 5 +array.last #=> 5 # With a start index and length array[2, 3] #=> [3, 4, 5] @@ -264,6 +268,12 @@ hash.each do |key, value| puts "#{key} is #{value}" end +# If you still need and index you can use "each_with_index" and define an index +# variable +array.each_with_index do |element, index| + puts "#{element} is number #{index} in the array" +end + counter = 1 while counter <= 5 do puts "iteration #{counter}" |