Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可以使用以下方法初始化 ruby 数组:
irb(main):01:0> Array[1,2,3] => [1, 2, 3]
我如何在自己的课堂上模仿这种行为?
您可以实现公共[](*args)类方法。
[](*args)
class Foo def self.[] *args new *args end # ... end