1 2 3 4
class WhoIsQuery query = ARGV[0] puts "Querying whois with #{query} ..." ...
Ruby Whois refactoring
I'm new to ruby and I make ...
1 2 3 4
def save_feed @feed = FeedTools::Feed.open('http://losangeles.craigslist.org/apa/index.rss') @feed.items.each_with_index do |item,i| ...
Ruby RSS model method
Its very simple method whic...
1 2 3 4
class Article < ActiveRecord::Base # Find all articles in the given date range based on the published_at field ...
Ruby Building a dynamic date range
I've got a route that handl...
1 2 3 4
<% @purchase_order.grants.each do |grant| %> <table> <tbody> ...
Ruby Please help me simplify thi...
Is there a way in Ruby to p...
1 2 3 4
class CampaignsController < ApplicationController before_filter :load_campaign_or_redirect, :except => [:index, :sent, :new, :queued, :create, :processing] ...
Ruby Step-REST uuuuugly controller
by Pożycz Badge,
April 23, 2008 16:01,
2 refactorings
Proably it's possible to cl...
1 2 3
class UserMailer < ActionMailer::Base def signup_notification(user) ...
Ruby before_filter in model???
I have to call the setup_em...
1 2 3 4
class VotingSystem #Hello, I am Rodger the old and unhappy programmer. the variable nbrOfVotes is an array of 2 dimensions. The first dimension contains the number of votes for the answer "YES, IT SUCKS"... and the other dimension contain the number of votes for the answer "NO, IT DOESN'T SUCK". In the near future there will be other possible answers... but I don't care! I retire in 2 days! @@nbrOfVotes = Array.new ...
Ruby Rubyize this : 6th edition
Ouch... this guy badly need...
1 2 3 4
def self.valid?(key) h=find_by_key(key) ...
Ruby Better Nest Ifs
by pcorral.myopenid.com,
April 13, 2008 03:02,
6 refactorings
Any idea about better code?
1 2 3 4
require 'erb' # GOAL: render the template with the following vars ...
Ruby Given a hash of variables, ...
by mislav,
April 12, 2008 15:12,
3 refactorings, tagged with erb, singleton, metaclass, metaprogramming, hash, render
This works. Now, is there a...
1 2 3 4
def assigned_to_id=(user_id) if user_id == "" if self.ticket_assigment != nil- ...
Ruby WTF
by prekitt.myopenid.com,
April 09, 2008 19:56,
1 refactoring, tagged with Ruby on rails activerecord
There's got to be a better ...
1 2 3 4
def hashify(object_array) h = Hash.new object_array.each do |x| ...
Ruby Less typing same functionality
I know this can be done but...
1 2 3
class Race < ActiveRecord::Base ...
Ruby Help generating abbreviatio...
by Michael Filbin,
April 06, 2008 16:16,
2 refactorings, tagged with abbreviation, string, model, attribute
Hi all,
I am attempting ...
1 2 3 4
require 'benchmark' def euler_chain_size(start) ...
Ruby Euler 14
The problem description is ...
1 2 3 4
class JobBoard < ActiveRecord::Base has_many :job_board_postings ...
Ruby Ruby has_finder on has_many ?
This smells... one of the m...
1 2 3 4
#!/usr/bin/env ruby # Simple Ruby XML Socket Server ...
Ruby AJAX Chat Socket Server
by Martindale,
March 28, 2008 18:39,
1 refactoring
Line 224, if I change this ...
1 2 3 4
@week_endings ||= Actual.get_week_endings(4.weeks.ago.to_date) 6.times do |p| actual = Actual.new ...
Ruby Appending future dates to t...
Line 1 I'm grabbing the mos...
1 2 3 4
# OPTIMIZE: I think we can do a LOT for optimize this. def create added_counter = 0 ...
Ruby Importing large collection ...
This scripts get textarea w...
1 2 3 4
def pearson(first,second) common = first.select{|title,rating| second.include?(title) } return if common.empty? ...
Ruby Pearson coefficient calcula...
by Brianthecoder,
March 13, 2008 14:08,
1 refactoring
This was ported from python...
1 2 3 4
class Hash def fetch_all(key) results = [] ...
Ruby Recursive Hash#fetch
I wanted a Hash#fetch that ...
1 2 3 4
%w[uri net/http hpricot].each {|lib| require lib} url = 'http://en.wikipedia.org/wiki/Night' response = Net::HTTP.get_response(URI.parse(url)) ...
Ruby Absolute links
by michael.twofish,
March 11, 2008 15:02,
No refactoring, tagged with URLs, absolute links, relative links
Converting all URLs in a re...
1 2 3 4
def create @partner = Partner.new(params[:partner]) if(params[:partner_request_id]) ...
Ruby Fat controller method
I came across this monster ...
1 2 3
ActionController::Routing::Routes.draw do |map| eval(File.open(File.dirname(__FILE__) + '/../path/to/another/routes/file.rb', 'r').read) end
Ruby Adding routes in an externa...
I'm trying to retain the ra...
1 2 3 4
def calculate_price_of_credits(credits) case credits when 1..5000 ...
Ruby Ugly method for calculating...
by mister,
March 07, 2008 17:53,
3 refactorings
very uglish method, please ...
make_activation_code and ma...