In Ruby, foo[bar, baz] is just the syntactic sugar for foo.[](bar, baz) . All you need is a method called [] .
By the way: you just need to look at the documentation, for example. for Set :
[](*ary)
Creates a new set containing these objects.
What is the documentation there.
Basically, all you need is
class Foo def self.[](*args, &block) new(*args, &block) end end
source share