Navigation Menu

Skip to content

Commit

Permalink
Reduced the number of literal aliases to the range that has actually …
Browse files Browse the repository at this point in the history
…seen personal use. With the massive savings in overhead, I was able to fit Array#fourty_two
  • Loading branch information
dhh committed Nov 21, 2008
1 parent 5b72c9b commit 9d8cc60
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
2 changes: 1 addition & 1 deletion activesupport/CHANGELOG
Expand Up @@ -64,7 +64,7 @@

* Added TimeZone #=~, to support matching zones by regex in time_zone_select. #195 [Ernie Miller]

* Added Array#second through Array#tenth as aliases for Array#[1] through Array#[9] [DHH]
* Added Array#second through Array#fifth as aliases for Array#[1] through Array#[4] + Array#fourty_two as alias for Array[41] [DHH]

* Added test/do declaration style testing to ActiveSupport::TestCase [DHH via Jay Fields]

Expand Down
26 changes: 3 additions & 23 deletions activesupport/lib/active_support/core_ext/array/access.rb
Expand Up @@ -43,29 +43,9 @@ def fifth
self[4]
end

# Equal to <tt>self[5]</tt>.
def sixth
self[5]
end

# Equal to <tt>self[6]</tt>.
def seventh
self[6]
end

# Equal to <tt>self[7]</tt>.
def eighth
self[7]
end

# Equal to <tt>self[8]</tt>.
def ninth
self[8]
end

# Equal to <tt>self[9]</tt>.
def tenth
self[9]
# Equal to <tt>self[41]</tt>. Also known as accessing "the reddit".
def fourty_two
self[41]
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions activesupport/test/core_ext/array_ext_test.rb
Expand Up @@ -15,17 +15,13 @@ def test_to
end

def test_second_through_tenth
array = (1..10).to_a
array = (1..42).to_a

assert_equal array[1], array.second
assert_equal array[2], array.third
assert_equal array[3], array.fourth
assert_equal array[4], array.fifth
assert_equal array[5], array.sixth
assert_equal array[6], array.seventh
assert_equal array[7], array.eighth
assert_equal array[8], array.ninth
assert_equal array[9], array.tenth
assert_equal array[41], array.fourty_two
end
end

Expand Down

39 comments on commit 9d8cc60

@alloy
Copy link
Contributor

@alloy alloy commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, nice. I wonder what kind of thread this will spawn :-)

@eet-nu
Copy link

@eet-nu eet-nu commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this be called fourty_second?

@masegraye
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lordy.

@devpopol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol!

@vlc
Copy link

@vlc vlc commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a useful addition. Could you also provide Array#[π] please as I would like to access the 4.14159th element of my arrays but I can’t find a way to. Many thanks

@datra
Copy link

@datra datra commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Danish humor :)

@wtn
Copy link

@wtn wtn commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to change it to Array#forty_two

@ledermann
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I could unsubscribe from specific github comment thread…

@devpopol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://www.reddit.com/r/programming/comments/7erjo/hot_on_the_heels_of_arrayfourth_rails_now_ships/

someone got to submit the link first.. heh..

@anildigital
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

@carllerche
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to propose the following patch:

class Fixnum

alias mult_before_the_answer * def *(other) return 42 if self == 6 && other == 8 mult_before_the_answer(other) end

end

@rmoriz
Copy link

@rmoriz rmoriz commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

April 1st already? 8→

@hojberg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rofl …. <3

@elia
Copy link
Contributor

@elia elia commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don’t touch second and third d2h! I already use (and love) them in a production app!!!

Best people always go first… :‘(
I miss you all sixth..tenth
And you, fourtytwo, don’t feel guilty_

@lackac
Copy link
Contributor

@lackac lackac commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, now if we could just find the right array to send this method to…

@monde
Copy link
Contributor

@monde monde commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that constitute an easter egg or just part of an easter egg shell?

@Roman2K
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is a joke, right?

@rmoriz
Copy link

@rmoriz rmoriz commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the “other” people’s republic of Counting (Province of Numbers) rates forty_two as offensive besides all ISO norms: Danger!

@datra
Copy link

@datra datra commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why you don’t want to run edge rails.

@unimatrixZxero
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the people complaining about Array#forty_two not aware of the cultural reference?

@neilh
Copy link

@neilh neilh commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not, why not

@augustl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, David! Finally Rails scales.

@vesan
Copy link
Contributor

@vesan vesan commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol @ rmoriz

@littlestarling
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you get if you multply six by nine? :)

@radar
Copy link
Contributor

@radar radar commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@littlestarling: 54.

@cpjolicoeur
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brilliant

@georgi
Copy link

@georgi georgi commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t like the syntax. For accessing “the Reddit” I’d rather prefer the explicit way:

```
Reddit::Thread.start do
loop do
Reddit::Comment.create
sleep 1
end
end
```

@dhh
Copy link
Member Author

@dhh dhh commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don’t spoil the joke of revealing the reference :).

Also, this will ship in Rails 2.2. Having this much power should not be available only to edge users.

@scottymac
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should be “forty”; one of a multitude of silly linguistic developments in English that makes no sense. I shudder to think what learning English as a second language must be like…

@sw0rdfish
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOOT! Finally!

Brilliant David! Love it!

@dhh
Copy link
Member Author

@dhh dhh commented on 9d8cc60 Nov 21, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was changed to forty_two in a later commit. And yes, scottymac, it’s a strange exception.

@virtualmice
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t panic !

(or should I panic ?)

@spiceee
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scottymac languages thrive on exceptions. English is possibly the easiest to learn as second language.

@ncr
Copy link
Contributor

@ncr ncr commented on 9d8cc60 Nov 22, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Good.

@ncr
Copy link
Contributor

@ncr ncr commented on 9d8cc60 Nov 22, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in Good vs. Evil.

@ianwhite
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def six_times_nine_if_i_had_thirteen_fingers
  self[41]
end

@littlestarling
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Radar: see “Answer to Life, the Universe and Everything”
http://tinyurl.com/6kbzkw

@josevalim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Merb guys will fix it now! =P

@Aupajo
Copy link
Contributor

@Aupajo Aupajo commented on 9d8cc60 Jan 5, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 @ianwhite

Please sign in to comment.