diff options
author | Kara Kincaid <kara_kincaid@epam.com> | 2015-10-13 10:06:11 -0400 |
---|---|---|
committer | Kara Kincaid <kara_kincaid@epam.com> | 2015-10-13 10:06:11 -0400 |
commit | 45a5a9ed5b45f483a04c3b985be74cbcd38179fe (patch) | |
tree | 9d7599079877adda1b28cac75b8bc8f8bf057091 /ruby.html.markdown | |
parent | 622d4485ab9efd265be83d16abbe8cb12da7934c (diff) | |
parent | 59a07411effbd0ed6289e062621deb29fe8641a8 (diff) |
fix merge conflict in css.html.markdown
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}" |