Skip to content

Instantly share code, notes, and snippets.

@richardiux
Created December 10, 2010 22:14
Show Gist options
  • Save richardiux/736911 to your computer and use it in GitHub Desktop.
Save richardiux/736911 to your computer and use it in GitHub Desktop.
Class that behaves like array
class A
def method_missing(method_sym, *arguments, &block)
if method_sym == :[] && arguments.first.is_a?(Integer)
# do something here with value (search something or create)
arguments.first
else
super
end
end
end
a = A.new
a[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment