https://github.com/condef5/ruby-workshop-i
https://github.com/condef5/ruby-workshop-i
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/condef5/ruby-workshop-i
- Owner: condef5
- Created: 2021-01-23T21:01:02.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-25T04:47:56.000Z (over 5 years ago)
- Last Synced: 2025-03-16T02:48:25.530Z (about 1 year ago)
- Language: Ruby
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Ruby Workshop
The purpose of these exercises is to train you on how to
use classes, operator overloading and linked list in ruby.
# Exercises
1. DPokemon
A DPokemon is a pokemon profile that shows the name and the power level of a particular pokemon.
In some cases, this pokemon meets other pokemons, and it wants to compare levels and know which is the strongest.
Your task here is to implement a DPokemon class and provide the necessary methods to compare the pokemon levels.
* Implement main class
```
lugia = DPokemon.new("lugia", 2000)
pikachu = DPokemon.new("pikachu", 2000)
```
* Implement equal method(==)
```
lugia == pikachu # false
```
* Implement stronger method(>)
```
lugia > pikachu # true
```
* Implement less strong method(<)
```
lugia < pikachu # false
```
2. FixedArray
A FixedArray is an array that always has a fixed number of elements.
Your task here is write a class that implements a fixed-length array, and provides the
necessary methods to support the following code:
* Implement main class
```ruby
fixed_array = FixedArray.new(5)
```
* Setting a element to position
```ruby
fixed_array[3] = 12
puts fixed_array # nil, nil, nil, 12, nil
```
* Retrieve an element
```ruby
fixed_array[3] # 12
```
* Support errors
```ruby
fixed_array[6] # raise an IndexError
```
* Convert to array
```ruby
puts fixed_array.to_a # [nil, nil, nil, 12, nil]
```
* Convert to string
```ruby
puts fixed_array.to_s # '[nil, "c", nil, "a", "d"]'
```
3. SuperFibo
Have you heard of Leonardo Pisano? Not yet? Don't worry, He invented a famous succession
```
0 1 1 2 3 5 8 13
```
Maybe now you have an idea, this is the fibonacci sequence.
Your task here will be to implement a fibonacci sequence with objects:
Example of code:
```ruby
zero = SuperFibo.new
one = zero.next
puts one.value # 1
another_one = one.next
puts another_one.value # 1
puts another_one.next.value # 2
puts another_one.next.next.value # 3
```
# Running the tests
After you finish an exercise, you need to go that exercise test in the `test` folder
and remove the comment operator, like this:
```diff
- class FixedArrayTest # < Minitest::Test
+ class FixedArrayTest < Minitest::Test
```
Then you can run the tests with this command:
```bash
rake test
```