1
2
3
4
# Ruby 1.8.6
pools = {1 => [1,2,3], 2 => [3,4,5], 3 => [5,6,7]}
values = pools.values.flatten
...

Ruby On Find the Intersection of Ar...

by Jeremy, July 31, 2008 21:59 Star_fullStar_fullStar_full

Here are a couple of option...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
class User
  named_scope :older_than, lambda { |u| { :conditions => ['age > u', u.age] } }
end
...

Ruby On How to make instance variab...

by Jeremy, July 31, 2008 14:21

If you're using Rails 2.1, ...

5170ca260dbd2cdfd5a887a4dba7636f Talk

Ruby On render partial layout

by Jeremy, July 31, 2008 14:08

Partials don't use the layo...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
event_times = events.collect { |event| event.datetime.strftime("%I:%M %p") }
times = times.reject { |time| event_times.include?(time.strftime("%I:%M %p'")) }

Ruby On two for loops cleanup?

by Jeremy, July 31, 2008 04:31 Star_fullStar_fullStar_fullStar_fullStar_full

I posted this refactoring e...

5170ca260dbd2cdfd5a887a4dba7636f Talk

Ruby On two for loops cleanup?

by Jeremy, July 31, 2008 00:17

see my post below...

5170ca260dbd2cdfd5a887a4dba7636f Talk

Ruby On Enumerable#cluster

by Jeremy, July 22, 2008 15:16

@Wolfbyte, good catch. I su...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
module Enumerable
  def cluster
    self.uniq.sort.map { |u| self.select { |v| u == v } }
...

Ruby On Enumerable#cluster

by Jeremy, July 22, 2008 02:04

This is a pretty clean one-...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
def all_shops(products)
  products.map(&:shops).flatten.uniq
end

Ruby On Squash a collection.

by Jeremy, July 07, 2008 13:47 Star_fullStar_fullStar_fullStar_fullStar_full

Daniel nailed it. If you're...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
def valid_param?(key)
  params[key] && params[key].length > 3
end
...

Ruby On Constructing a search query

by Jeremy, July 07, 2008 13:44

Slight correction to Pablo'...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
{
  "0" => "24142",
  "1" => "15151",
...

Ruby On Looking for comments on sty...

by Jeremy, June 20, 2008 17:19

Instead of case/when/then, ...

5170ca260dbd2cdfd5a887a4dba7636f Talk