Skip to content
This repository
Browse code

Reduced the number of literal aliases to the range that has actually …

…seen personal use. With the massive savings in overhead, I was able to fit Array#forty_two
  • Loading branch information...
commit e50530ca3ab5db53ebc74314c54b62b91b932389 1 parent 1d4554d
David Heinemeier Hansson dhh authored
2  activesupport/CHANGELOG
@@ -70,7 +70,7 @@
70 70
71 71 * Added TimeZone #=~, to support matching zones by regex in time_zone_select. #195 [Ernie Miller]
72 72
73   -* Added Array#second through Array#tenth as aliases for Array#[1] through Array#[9] [DHH]
  73 +* Added Array#second through Array#fifth as aliases for Array#[1] through Array#[4] + Array#forty_two as alias for Array[41] [DHH]
74 74
75 75 * Added test/do declaration style testing to ActiveSupport::TestCase [DHH via Jay Fields]
76 76
26 activesupport/lib/active_support/core_ext/array/access.rb
@@ -43,29 +43,9 @@ def fifth
43 43 self[4]
44 44 end
45 45
46   - # Equal to <tt>self[5]</tt>.
47   - def sixth
48   - self[5]
49   - end
50   -
51   - # Equal to <tt>self[6]</tt>.
52   - def seventh
53   - self[6]
54   - end
55   -
56   - # Equal to <tt>self[7]</tt>.
57   - def eighth
58   - self[7]
59   - end
60   -
61   - # Equal to <tt>self[8]</tt>.
62   - def ninth
63   - self[8]
64   - end
65   -
66   - # Equal to <tt>self[9]</tt>.
67   - def tenth
68   - self[9]
  46 + # Equal to <tt>self[41]</tt>. Also known as accessing "the reddit".
  47 + def forty_two
  48 + self[41]
69 49 end
70 50 end
71 51 end
8 activesupport/test/core_ext/array_ext_test.rb
@@ -15,17 +15,13 @@ def test_to
15 15 end
16 16
17 17 def test_second_through_tenth
18   - array = (1..10).to_a
  18 + array = (1..42).to_a
19 19
20 20 assert_equal array[1], array.second
21 21 assert_equal array[2], array.third
22 22 assert_equal array[3], array.fourth
23 23 assert_equal array[4], array.fifth
24   - assert_equal array[5], array.sixth
25   - assert_equal array[6], array.seventh
26   - assert_equal array[7], array.eighth
27   - assert_equal array[8], array.ninth
28   - assert_equal array[9], array.tenth
  24 + assert_equal array[41], array.fourty_two
29 25 end
30 26 end
31 27

12 comments on commit e50530c

Kerry Buckley

Did you forget to run the test after correcting fourty_two to forty_second? ;-)

Matthew Rudy Jacobs

great, I’ve been waiting for this for ages.

Joost Baaij

I am sure I am not getting this.

Ryan Bigg

This should be Array#forty_second

Amos King

Ok, ok. This is funny. Thanks for reducing the overhead from your previous version.

Henrik Nyh

tilsammans: http://en.wikipedia.org/wiki/Notable_phrases_from_The_Hitchhiker%27s_Guide_to_the_Galaxy#Answer_to_Life.2C_the_Universe_and_Everything_.2842.29

Jason Roelofs

Awesome, though now we’re missing Array#six and Array#nine.

Justin Blake

Great, now I’ll have to alias_method_chain this to forty_second…

Renaud Morvan

Don’t need Array#thirty_seven too ?

Charlie O'Keefe

Um, shouldn’t test_second_through_tenth be renamed to test_second_through_fifth?

Caleb Cullen

Does your test succeed? The method is misspelled, using a ‘u’ where no ‘u’ should be.

Cute, tho’. Nice tip o’ the hat to the late Mr. Adams. Just started re-reading those books. What about 23, 37, and all those other important numbers? ;)

BTW, who uses ‘fourth’ or even ‘third’? (‘fifth’ is right out)

#first makes a lot of sense, #last is useful…

Zack Hobson

@radar is right, this should be Array#forty_second.

Please sign in to comment.
Something went wrong with that request. Please try again.