我在erb库中遇到了以下代码.注意双(( )):
class MyTest
def location=((filename, lineno))
@filename = filename
@lineno = lineno if lineno
end
end
Run Code Online (Sandbox Code Playgroud)
以下locatia=方法是没有(( ))for测试的另一个版本:
class MyTest
def locatia=(filename, lineno)
@filename = filename
@lineno = lineno if lineno
end
end
Run Code Online (Sandbox Code Playgroud)
我得到了这个结果:
a = MyTest.new
a.location = "foo", 34
a # => #<MyTest:0x2a2e428 @filename="foo", @lineno=34>
b = MyTest.new
b.location = "foo"
b # => #<MyTest:0x2a2e338 @filename="foo">
c = MyTest.new
c.locatia = "foo", 34
c # >> `locatia=': wrong number of arguments …Run Code Online (Sandbox Code Playgroud) 我需要为图形和分析准备一些数据,并可以使用一些建议来转换数据.
我有一个数组数组.每个子数组是一组收集的数据,最后一个元素代表所有数据的最新数据.早期元素代表历史数据.子阵列具有可变数量的历史.我想处理数组,以便当前数据(每个子数组中的最后一个元素)与右边界对齐.
例如:
[[2], [3, 5, 8, 9], [2, 10]]
Run Code Online (Sandbox Code Playgroud)
应转换为或处理,如同:
[[nil, nil, nil, 2], [3, 5, 8, 9], [nil, nil, 2, 10]]
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我宁愿不改变原始数据,但是如果它有帮助可以处理它(我只是首先对数组进行full_dup并处理副本)