通过查看文件ActiveRecord的active_record/relation/finder_methods.rb源代码,我发现了一些奇怪的东西(为简洁而编辑的代码)。
def second
find_nth(:second, offset_value ? offset_value + 1 : 1)
end
def second!
second or raise RecordNotFound
end
def third
find_nth(:third, offset_value ? offset_value + 2 : 2)
end
def third!
third or raise RecordNotFound
end
def fourth
find_nth(:fourth, offset_value ? offset_value + 3 : 3)
end
def fourth!
fourth or raise RecordNotFound
end
def fifth
find_nth(:fifth, offset_value ? offset_value + 4 : 4)
end
def fifth!
fifth or raise RecordNotFound
end
def forty_two
find_nth(:forty_two, offset_value ? offset_value + 41 : 41)
end
def forty_two!
forty_two or raise RecordNotFound
end我能理解第一和最后的方法,但第二、第三、第四等没有多大意义。此外,世界纪录从第五位跃升至第四十二位.您可以继续编写用于选择特定位置记录的糖方法。
有什么特别的原因吗?
发布于 2015-07-28 09:36:24
这是科幻小说对42被揭示为生命、宇宙和一切的答案。 in “银河系旅行者指南”的引用
任何时候只要选择一个不太大的任意数字,很多科幻迷就会选择42
https://stackoverflow.com/questions/31669862
复制相似问题