3 Replies - 4262 Views - Last Post: 19 September 2012 - 11:29 AM Rate Topic: -----

#1 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1383
  • View blog
  • Posts: 3,514
  • Joined: 28-November 09

Ruby Tricks

Posted 15 September 2012 - 11:59 PM

I've decided to start up some Ruby Tricks on Twitter and the like. If I find anything useful or relevant, you can find it under @keystonelemur with #rubytricks.

One of the latest fun bits I came across:
(1..5).each.inject(:*)


...is equivalent to 5!. A word to the wise, don't go above 10,000 lest you lag your computer mostly to death.

Anyone else want in on this string? It's my hope that we can get some clever pieces of code out there, simple one liners with some serious power. Either way, I'll still be posting.

Is This A Good Question/Topic? 0
  • +

Replies To: Ruby Tricks

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,311
  • Joined: 21-June 11

Re: Ruby Tricks

Posted 16 September 2012 - 06:34 AM

Why the .each? And how exactly is this a trick? Using a method for exactly the purpose it was intended for doesn't seem very tricky. (Not meaning to dis you or anything - just curious).

Unless you're saying using inject is inherently clever because the method is sort of obscure, which I guess I can kind of see...
Was This Post Helpful? 0
  • +
  • -

#3 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1383
  • View blog
  • Posts: 3,514
  • Joined: 28-November 09

Re: Ruby Tricks

Posted 16 September 2012 - 11:11 AM

Mainly just making short snippets that do something clever that not many people know of. In another light, it's showing things in a new way.
Was This Post Helpful? 0
  • +
  • -

#4 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Ruby Tricks

Posted 19 September 2012 - 11:29 AM

You might get a kick out of this vid, Lemur, it's got about 20 cool ruby tricks in it. I'm not sure if Peterc wrote the book yet or not though.

http://www.youtube.c...h?v=gIEMKOI_Y-4
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1