How to pass argument to the method definition of `[]`?

  • A+
Category:Languages

How can I pass an argument to the definition of a singleton method of [] on A, in other words A['some_argument']?

class A   def self.[]     # some_argument   end end 

 


Just as to any other method, using argument list:

class A    def self.[](arg)     puts arg   end   end    A[1] # => 1 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: