I am trying to explain what can Ruby do essentially. I hope with this exercise, I am able to solve problem better because I know what can a programming language do at the basic level.
Key data types
1. Strings
2. Numbers
3. Symbols
4. Nil
5. Boolean - true or false
Key data structures
1. Arrays
2. Hashes
3. Range
General Key Operations
Comparison between two data type
Ruby can compare between two data.
1. == comparison whether two data is equal.
2. >= large than
3. <= lower than
4. equals - compare whether two object are the same object (ie. pointing to the same data)
Logic operation
1. && - logical AND that needs both to be TRUE before returning true.
2. || - logical OR that needs either one of them to be TRUE before returning true.
Convert data types
1. convert Strings into Numbers (using #to_i)
2. convert Numbers into Strings (using #to_s)
3. All data types evaluates to TRUE except nil and false.
4. convert Arrays into Strings (using #join)
5. convert Strings into Arrays (using #split)
6. In order to convert an Number to Array of Integers (use #to_s > #chars > #map(&:to_i)
7. There are no direct methods for convert any data types into a Hash.
8 convert Array to a Hash (using #to_h)
9. convert Range into Array (using #to_a)
Assignment
We can assign a value to a variables using the #= method
Input/Output
Ruby can get input from user using #gets and output information using #puts , #print or #p.
Code Path
- In general code executes from top to bottom. Code interpreter will ignore method/class definition. Your method call or object instantiation needs to start after the class/method definition
1. decision-path (flow control)
Able to direct code execution path using if/else , case statement, unless , ternary statement. It needs to evaluate a statement then run certain other statement.
2. looping-path
Able to execute a code over and over again. Often combined with a decision-path to decide when to break the loop.
Variable scopes
There are four types of variables in Ruby, local variables/constant variables/global variables/class variables/instance variables.
These are variation are decision made on where/when can they be used and whether they are changeable.
Most of the methods are performed on data. It is manipulating data in some ways. That's why any methods depends on the data it is called upon.
Numbers Operations
Mathematical operation
1. including addition, subtraction, division, modulus and multiplication.
2. basic mathematical operation like floor, ceiling.
Strings Operations
1. You can delete any characters in a string.
2. You can find and replace any characters in a string.
3. You can convert any character into uppercase or lowercase.
4. You can iterate through the string
5. You can split the strings by a delimiter.
6. You can count the numer of characters in a string.
7. You can check whether a sample is included in the string (#include? population.include?sample)
8. You can insert any values into any index position.
Array
1. You can modify each element in the array.
2. You put stuff into the array from the front and back.
3. You can make the array element unique.
4. You can iterate through the element one by one. Either return whatever is being evaluated, or the original array.
5. You can delete any elements in the array.
6. You can retrieve any elements in the array.
7. You can select elements in an array that meet certain criteria.
8. You can check whether a sub-elements is included in the array (#include -> population.include?sample)
9. You can sort the elements in the array.
10. You can merge two arrays together
11. You can count the number of elements in an Array.
12. You can insert any values into any index position.
Hash
1. You can merge two hashes together
2. You can retrieve information from each Hash key/value pairs.
3. You can delete any key/value pairs in a Hash.
4. You can select any key/value pairs that satisfy certain criteria.
5. You can retrieve all key or all values of a Hash into an Array.
6. You can count the number of key/value pairs in a Hash.
Method
No more than a list of instruction for the computer to perform.
Key data types
1. Strings
2. Numbers
3. Symbols
4. Nil
5. Boolean - true or false
Key data structures
1. Arrays
2. Hashes
3. Range
General Key Operations
Comparison between two data type
Ruby can compare between two data.
1. == comparison whether two data is equal.
2. >= large than
3. <= lower than
4. equals - compare whether two object are the same object (ie. pointing to the same data)
Logic operation
1. && - logical AND that needs both to be TRUE before returning true.
2. || - logical OR that needs either one of them to be TRUE before returning true.
Convert data types
1. convert Strings into Numbers (using #to_i)
2. convert Numbers into Strings (using #to_s)
3. All data types evaluates to TRUE except nil and false.
4. convert Arrays into Strings (using #join)
5. convert Strings into Arrays (using #split)
6. In order to convert an Number to Array of Integers (use #to_s > #chars > #map(&:to_i)
7. There are no direct methods for convert any data types into a Hash.
8 convert Array to a Hash (using #to_h)
9. convert Range into Array (using #to_a)
Assignment
We can assign a value to a variables using the #= method
Input/Output
Ruby can get input from user using #gets and output information using #puts , #print or #p.
Code Path
- In general code executes from top to bottom. Code interpreter will ignore method/class definition. Your method call or object instantiation needs to start after the class/method definition
1. decision-path (flow control)
Able to direct code execution path using if/else , case statement, unless , ternary statement. It needs to evaluate a statement then run certain other statement.
2. looping-path
Able to execute a code over and over again. Often combined with a decision-path to decide when to break the loop.
Variable scopes
There are four types of variables in Ruby, local variables/constant variables/global variables/class variables/instance variables.
These are variation are decision made on where/when can they be used and whether they are changeable.
Most of the methods are performed on data. It is manipulating data in some ways. That's why any methods depends on the data it is called upon.
Numbers Operations
Mathematical operation
1. including addition, subtraction, division, modulus and multiplication.
2. basic mathematical operation like floor, ceiling.
Strings Operations
1. You can delete any characters in a string.
2. You can find and replace any characters in a string.
3. You can convert any character into uppercase or lowercase.
4. You can iterate through the string
5. You can split the strings by a delimiter.
6. You can count the numer of characters in a string.
7. You can check whether a sample is included in the string (#include? population.include?sample)
8. You can insert any values into any index position.
Array
1. You can modify each element in the array.
2. You put stuff into the array from the front and back.
3. You can make the array element unique.
4. You can iterate through the element one by one. Either return whatever is being evaluated, or the original array.
5. You can delete any elements in the array.
6. You can retrieve any elements in the array.
7. You can select elements in an array that meet certain criteria.
8. You can check whether a sub-elements is included in the array (#include -> population.include?sample)
9. You can sort the elements in the array.
10. You can merge two arrays together
11. You can count the number of elements in an Array.
12. You can insert any values into any index position.
Hash
1. You can merge two hashes together
2. You can retrieve information from each Hash key/value pairs.
3. You can delete any key/value pairs in a Hash.
4. You can select any key/value pairs that satisfy certain criteria.
5. You can retrieve all key or all values of a Hash into an Array.
6. You can count the number of key/value pairs in a Hash.
Method
No more than a list of instruction for the computer to perform.
Comments
Post a Comment