If I understand the question, you want a method that takes any number of arguments, and returns an object that will create a range of numbers when the [] method is used.
This method takes any number of arguments (using the * splat operator), and then returns a proc, which [] can be used on.
def some_named_function(*args)
  proc do |length|
    # Do something with the args?
    (0..length).to_a
  end
end
And then it can be used like this:
some_named_function[3] # => [0, 1, 2, 3]
some_named_function('optional', 'args')[1] # => [0, 1]
0
solved Calling #[] on a ruby method [closed]