1 2 3 4
object.constraints.each do |c| p = object.particles[c.index] if c.component == :x ...
Ruby ruby metaprogramming
1 2 3 4
class Light def initialize(location) @location = location ...
Ruby Command Pattern from Head F...
Example in Ruby of Command ...
1 2 3 4
brew = "rdadadroxmocpronogomocdmqzx" alphabet = "abcdefghijklmnopqrstuvwxyz" word = "" ...
Ruby Newb needs some cleanup
Some code I've written for ...
1 2 3 4
require 'rubygems' require 'hpricot' ...
Ruby Screen Scraping Google with...
by zigx.myopenid.com,
December 18, 2008 00:48,
7 refactorings, tagged with ruby, hpricot, watir, google, scrape
Would love to see a COOLer ...
1 2 3 4
# sum an an array's elements def sum_row(a) sum = 0 ...
Ruby Conditionally deleting colu...
I needed to read in a CSV f...
1 2 3 4
get '/:id' do @vent = Vent.get(params[:id]) erb :show ...
Ruby Trying to condence 2 method...
by Jason Calleiro,
December 10, 2008 21:53,
5 refactorings, tagged with ruby, sinatra, rails, rest, xml
Currently using sinatra fra...
1 2 3 4
#!/usr/bin/env ruby -wKU require 'rubygems' require 'net/http' ...
Ruby Web2.0 Domain Name Generator
This generates a text file ...
1 2 3 4
array_with_blank_strings.compact.reject(&:blank?) >> array_with_blank_strings = ["Item 1", "Item 2", " ", "Item 3", nil] ...
Ruby Strip blank Strings and Nil...
This code will firstly remo...
1 2 3 4
# camera related def frame_diagonal(frame_horizontal, frame_vertical) @frame_diagonal = Math.sqrt((frame_horizontal**2) + (frame_vertical**2)) ...
Ruby Photograhy methods
by sfusion.myopenid.com,
December 05, 2008 11:42,
1 refactoring, tagged with photography, camera, lens, ruby, math
Any comments, corrections, ...
1 2 3 4
def factorial( n ) if !(n.is_a? Integer) raise ArgumentError, "argument must be a positive integer" ...
Ruby A simple factorial program.
by lordzoner.myopenid.com,
November 12, 2008 02:16,
7 refactorings, tagged with short, ruby, factorial
I'm quite new to Ruby, and ...
1 2 3 4
for directory in @directories xml.item do xml.title "#{directory.name} (PR #{directory.pagerank})" ...
Ruby xml rss feed
by chovy.myopenid.com,
November 05, 2008 07:13,
2 refactorings, tagged with Ruby on Rails, proc, xml, ruby
Looking for a better way to...
1 2 3 4
def compress(source) source.gsub!(/\s+/, " ") # collapse space source.gsub!(/\/\*(.*?)\*\//, "") # remove comments - caution, might want to remove this if using css hacks ...
Ruby Gsubing
There is a lot of repetitio...
1 2 3 4
def translation_links lang = [ %w[en english us], ...
Ruby nested array to set of html...
i have a simple array that ...
1 2 3
# Simple method to calculate the square of a number
...
Ruby Conditional Assignment
This is a tiny bit of code ...
1 2 3
feed = RssParser.run("http://ws.audioscrobbler.com/1.0/user/me/recenttracks.rss") song1 = feed[:items][0][:title] ...
Ruby Think this needs a loop
Im new to Ruby, I think it ...
1 2 3
class Administration::ReportsController < Administration::HomeController ...
Ruby has_many :through collectio...
by kain,
August 30, 2008 01:53,
No refactoring, tagged with Ruby on Rails, rails, ruby, has many through
This is an attempt to make ...
1 2 3 4
class Report < ActiveRecord::Base belongs_to :reportable, :polymorphic => true ...
Ruby A shorter way to declare cl...
I added these so I could re...
1 2 3
artists = [1, 2, 3] column_1 = artists[0..artists.size/2] column_2 = artists[artists.size/2+1..artists.size]
Ruby Split an array into half
The example works if the ar...
1 2 3 4
if @events != nil @events.each do |event| if @recurrents != nil ...
Ruby superfluous if statements
I'm pretty sure theres a be...
1 2 3 4
require 'csv' def sort_csv(filename, fields = ["ID"], reverse = false) ...
Ruby Ruby Custom Sort
I had this question recentl...
1 2 3 4
# generate_bf.rb # (copyleft) Matt Gauger 2008 # Randomly generates a brainfuck program ...
Ruby Brainfuck Generator in Ruby
Probably better ways to do ...
1 2 3 4
times.each do |time| events.each do |event| if time.strftime("%I:%M %p") == event.datetime.strftime("%I:%M %p") ...
Ruby two for loops cleanup?
times is an array of dateti...
1 2 3 4
i = 0 for j in ['foo', 'bar', 'baz'] puts "#{i} #{j}" ...
Ruby Python's enumerate in Ruby?
by robby86533.identity.net,
July 14, 2008 23:02,
3 refactorings, tagged with python, ruby, for, enumerate
What is the best way to emu...
So here here my ugly code. ...