3 ms·
Rails – #forty_two() method
- bowmessage 12y agoLooks like it was merged in on January 20th: https://github.com/rails/rails/pull/13757 https://github.com/rails/rails/pull/13757
- caniscrator 12y agoThe answer to life the universe and everything !
- MrBra 12y agopft
- cookrn 12y agoFun! This can also be found as a general array accessor: https://github.com/rails/rails/blob/ed03d4eaa89a7b4ab09e7f5da76b522d04650daf/activesupport/lib/active_support/core_ext/array/access.rb#L58-L63 https://github.com/rails/rails/blob/ed03d4eaa89a7b4ab09e7f5d... Here's another interesting one from ActiveSupport giving Ruby Numerics the ability to be treated as various quantities of bytes: https://github.com/rails/rails/blob/9eeb5fed2ff8e781e56202f62b125bfadc486999/activesupport/lib/active_support/core_ext/numeric/bytes.rb https://github.com/rails/rails/blob/9eeb5fed2ff8e781e56202f6...
- rfw 12y agoIt seems odd that ActiveRecord even has the methods #first through to #fifth...
- oldmanjay 12y agoI am familiar with this reference!
- mrweasel 12y agoI think there was a talk by David Heinemeier Hansson where he talks about this. I believe it's mainly put in to annoy someone.
- mbesto 12y agoHaha. Genuine question - why are nth methods available in ActiveRecord? Basically anything past .first doesn't seem necessary (functionally speaking).
- mrweasel 12y agoI don't know, I'm not a Ruby/Rails guy. I just remember seeing something where DHH talked about this.
- mackwic 12y agoIt's the whole philosophy of ruby: sometimes, it makes more sense to write the index in full letters rather than in digits.
- briandear 12y agoI feel the same way about empty parenthesis and line ending semicolons. Lol.
- ghayes 12y agoFor me, it comes up in test cases. In a controlled environment, it can be nice to mentally say "add two objects, the first should be this, the second should be this." I don't think I've ever used `second` outside of the testing realm.
- briandear 12y agoThis was put in as a result of a folks complaining about .second and similar array sugar. I don't have the link to the Github thread from 8 years ago, but I remember it was prodigiously awesome.