Skip to content

Instantly share code, notes, and snippets.

@kushniryb
Last active November 4, 2016 23:24
Show Gist options
  • Save kushniryb/3a1c45f70f1dab6d54288dacf9c21604 to your computer and use it in GitHub Desktop.
Save kushniryb/3a1c45f70f1dab6d54288dacf9c21604 to your computer and use it in GitHub Desktop.
Kottans Homework #2 [Enumerable / Comparable / Enumerators]

Task 1: Comparable

Create a superhero class with the following attributes:

  • name
  • strength *
  • agility *
  • intelligence *

You should be able to compare different superheroes based on the avarage of attributes marked with *

Display the list of superheroes sorted by an average, as well as by each of the attributes marked with *

Task 2: Enumerable

You can't deal with everything on your own, that's why a superhero needs a Team.

Implement a Team class which acts as a collection of superheroes so that you can call Enumerable methods on it

Anticipate a situation where no block is provided

Also, create your own enumerable module which implements following methods:

  • select
  • reduce
  • maxmin

Task 3: Enumerators

Construct an infinite list enumerator which would return first n sqaured values(1 < n < 10_000)

Think about an elegant way to implement following methods:

  • each_with_object [Note: Yes, I know it's present in the Enumerable. We'd like to see an alternative implementation via different enumerators]
  • map_cons
  • reverse_cycle_map [Note: without using Array#reverse method]

Read about Fiber

Each task has to include RSpec tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment