Skip to content

Instantly share code, notes, and snippets.

@samleb
Created June 5, 2009 04:39
Show Gist options
  • Select an option

  • Save samleb/124059 to your computer and use it in GitHub Desktop.

Select an option

Save samleb/124059 to your computer and use it in GitHub Desktop.
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