Created
June 5, 2009 04:39
-
-
Save samleb/124059 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Enumerable | |
| module Ordonned | |
| def [](arg) | |
| case arg | |
| when Numeric | |
| detect.with_index { |_, index| index == arg } | |
| when Range | |
| result = [] | |
| each.with_index do |object, index| | |
| result << object if arg.include?(index) | |
| end | |
| result | |
| else | |
| raise ArgumentError, "Range or Numeric expected" | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment