Skip to content

condef5/ruby-workshop-I

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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
  1. 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
fixed_array = FixedArray.new(5)
  • Setting a element to position
fixed_array[3] = 12
puts fixed_array # nil, nil, nil, 12, nil
  • Retrieve an element
fixed_array[3] # 12
  • Support errors
fixed_array[6] # raise an IndexError
  • Convert to array
puts fixed_array.to_a # [nil, nil, nil, 12, nil]
  • Convert to string
puts fixed_array.to_s # '[nil, "c", nil, "a", "d"]'
  1. 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:

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:

- class FixedArrayTest # < Minitest::Test
+ class FixedArrayTest < Minitest::Test

Then you can run the tests with this command:

rake test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages