Ruby
From WikiZMSI
Spis treści |
[edytuj]
Part 1 - Introduction
- Ruby website for developers. Access to documentation and downloads Ruby.
- List of different books & tutorials:
[edytuj]
To do
- Start with tutorial Try Ruby
- Visit the web Ruby Tutorial and study:
- Syntax
- Operators
- Comments
- IF... ELSE
- Loops
- Methods
- Blocks
[edytuj]
Part 2 - More syntax
[edytuj]
To do
- Visit the web Ruby Tutorial and study:
- Classess
- Modules
- Variables
- Strings
- Arrays
- Hashes
- Date&time
- Ranges
- Iterators
[edytuj]
Excercies
- Write a method that counts down to zero using recursion.
- Use the each_with_index method to iterate through an array of your creation that prints each index and value of the array.
- Write a method that uses recursion to calculate the nth number in the fibonacci sequence.
- Use the each method of Array to iterate over [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], and print out each value.
- Same as above, but only print out values greater than 7.
- Using the same array, use the select method to extract all odd numbers into a new array.
- Append "11" to the end of the original array. Prepend "0" to the beginning.
- Get rid of "11". And append a "3".
- Get rid of duplicates without specifically removing any one value.
- Write a program that checks to see if the number appears in the array. A number and the array are given.
- 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.
- Write a program that prints only even numbers grater than 10 and lower than 100 from the array. The array are given.
- Create a Hash using both Ruby syntax styles.
- 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.
- What method could you use to find out if a Hash contains a specific value in it? Write a program to demonstrate this use.
- What is the difference between merge and merge!? Write a program that uses both and illustrate the differences.
- Write a program which keep in the hash words and the number of their appearance in the given sentence.
- 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.
- 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']