给出一个类:命名Ruby方法
class Shell
attr_reader :spiral
def initialize spiral
@spiral = spiral
end
def ?????
# do stuff...
end
end
some_shell = Shell.new([[1,2],[4,3])
some_shell.spiral #=> [[1,2],
# [4,3]]
some_shell.????? #=> [1,2,3,4]
是否更有意义的名字?????
:
unwrap_spiral
或
unwrapped_spiral
好像unwrap_spiral
是说给some_shell
, “我想让你解开那个螺旋”,并且unwrapped_spiral
说some_shell
,“我希望你给我一个解开螺旋”。
我POODR阅读:
询问发件人想要的消息,并告诉接收机如何做人看似细微,但其后果是显著的消息之间的区别。
看起来好像选择unwrapped_spiral
会更好。
这有道理吗?
那去会是我的哲学也是如此。请注意,'unwrap'不仅仅是'flatten'。 –
感谢您的回复。澄清'some_shell。''有意“解开”而不是“扁平化”。那是我想要的:'[1,2,3,4]'不''[1,2,4,3]' – mbigras
啊。然后,我只是让'#unwrap' - >'flatten.sort' :) –