Tag: ruby+rails
-
Java + Ruby
I’m going to write a bit about Ruby in Java land. Much of this post stems from the Sun stall at FOSS.in: to put it mildly, it was perhaps the most enthusiastic stall I’ve seen at a conference ever. The energy of the guys there was incredible and their enthusiasm to show things off (and […]
-
Ruby Magic: Metaprogramming
Rails, if you’ve used it, has a rather elegant way of manipulating time. Stuff like 1.hours and 2.minutes.from_now just work. Let’s see how Ruby modules can be extended really really easily: #! /usr/bin/env ruby class Integer def seconds self end def minutes seconds * 60 end def hours minutes * 60 end def days hours […]
-
Ruby Magic: Blocks
I’ve been using Ruby a lot lately, and recently had to implement a “related” objects feature in Rails. You know, “Related Videos”, “Related Pages”, etc. I decided to sort them by objects that have the most common tags. Try this one-liner: #Inside video.rb Model, Related videos def related(count=5) tags.collect { |tag| tag.videos }.flatten.uniq.sort_by { |video| […]