Skip to content

Instantly share code, notes, and snippets.

@agnel
Forked from borowskiio/marray.rb
Created February 16, 2016 10:35
Show Gist options
  • Save agnel/a163d2403ad822519736 to your computer and use it in GitHub Desktop.
Save agnel/a163d2403ad822519736 to your computer and use it in GitHub Desktop.
Produce PHP-style multidimensional array, e.g arr[1][2][3] = 'foobar'
# Produce PHP-style multidimensional array.
#
# Example
#
# arr = Marray.new
#
# arr[1][2][3] = "foo"
# => "foo"
#
# arr[1][2][3]
# => "foo"
class Marray < Array
def [](i)
super.nil? ? self[i] = Marray.new : super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment