【发布时间】:2011-03-23 12:28:40
【问题描述】:
在 C# 中,您可以编写这样的扩展方法:
public static Debt[] Foo(this Debt[] arr, int num)
{
// Do something
}
这将允许您在一系列债务上使用Foo():debts.Foo(3)
你能在 Ruby 中做到这一点吗?我知道你可以编写一个适用于数组的方法:
class Array
def foo
# blah
end
end
但这适用于所有类型的数组,而不仅仅是Debts的数组
提前致谢。
【问题讨论】: