Skip to content

Instantly share code, notes, and snippets.

@slawosz
Created August 17, 2015 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slawosz/ac78515e71d711c0784e to your computer and use it in GitHub Desktop.
Save slawosz/ac78515e71d711c0784e to your computer and use it in GitHub Desktop.

Using class knowledge (see ie rental code we wrote create simple class) create a class MyRange that has following methods:

range = MyRange.new(2,6)

range.min #=> 2
range.max #=> 6

range.to_a #=> [2,3,4,5,6]

As a first bonus allow special constructor:

range = MyRange.new(min: 2, max: 6)

This gist will help to understand it: https://gist.github.com/slawosz/8db7fc43e01b9d003564

As a second bonus explore method next:

1.next #=> 2
"A".next #=> "B"

Use this method to be able to create range from any object that supports method next:

range = MyRange.new("A","B")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment