Ruby

From WikiZMSI

Spis treści

Part 1 - Introduction

  1. Ruby website for developers. Access to documentation and downloads Ruby.
  2. List of different books & tutorials:
    1. Learn Ruby the hard way
    2. Why’s (Poignant) Guide To Ruby
    3. Ruby Language Explained
    4. Ruby Learning by Satish Talim
    5. Introduction to Programming with Ruby
    6. Ruby Use's Guide

To do

  1. Start with tutorial Try Ruby
  2. Visit the web Ruby Tutorial and study:
    1. Syntax
    2. Operators
    3. Comments
    4. IF... ELSE
    5. Loops
    6. Methods
    7. Blocks

Part 2 - More syntax

To do

  1. Visit the web Ruby Tutorial and study:
    1. Classess
    2. Modules
    3. Variables
    4. Strings
    5. Arrays
    6. Hashes
    7. Date&time
    8. Ranges
    9. Iterators

Excercies

  1. Write a method that counts down to zero using recursion.
  2. Use the each_with_index method to iterate through an array of your creation that prints each index and value of the array.
  3. Write a method that uses recursion to calculate the nth number in the fibonacci sequence.
  4. Use the each method of Array to iterate over [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], and print out each value.
    1. Same as above, but only print out values greater than 7.
    2. Using the same array, use the select method to extract all odd numbers into a new array.
    3. Append "11" to the end of the original array. Prepend "0" to the beginning.
    4. Get rid of "11". And append a "3".
    5. Get rid of duplicates without specifically removing any one value.
  5. Write a program that checks to see if the number appears in the array. A number and the array are given.
  6. Write a program that iterates over an array and builds a new array that is the result of incrementing each value in the original array by a value of 2. You should have two arrays at the end of this program, The original array and the new array you've created.
  7. Write a program that prints only even numbers grater than 10 and lower than 100 from the array. The array are given.
  8. Create a Hash using both Ruby syntax styles.
  9. Using some of Ruby's built-in Hash methods, write a program that loops through a hash and prints all of the keys. Then write a program that does the same thing except printing the values. Finally, write a program that prints both.
  10. What method could you use to find out if a Hash contains a specific value in it? Write a program to demonstrate this use.
  11. What is the difference between merge and merge!? Write a program that uses both and illustrate the differences.
  12. Write a program which keep in the hash words and the number of their appearance in the given sentence.
  13. Write a program that checks if the sequence of characters e.g. th exists in the string. If it does exist, print out the word.
  14. Use Ruby's Array method delete_if and String method start_with? to delete all of the words that begin with an "s" in the following array.
arr = ['snow', 'winter', 'ice', 'slippery', 'salted roads', 'white trees']