Given /^The Navigation API is running$/ do
begin
@response = get('servicestatus', 'text/plain')
...
Ruby Step Definition
by https://www.google.com/accounts/o8/id?id=AItOawnvtFGh-r9ibK5ZHTYiZh2UzxDww7-bwI0,
October 08, 2011 05:19,
No refactoring
test "should not save with name > 60 chars" do
name = ""; name << 61.times.each{|x| name << "a"}
@author.name = name
...
Ruby validates length of in rails
what's better idea for this?
def steps
unless @steps
if scenario.class == Cucumber::Ast::OutlineTable::ExampleRow
...
Ruby unless.. if..
by https://www.google.com/accounts/o8/id?id=AItOawmZADKQPpupLegafoFEaOnWDyZ6Kd_VfMI,
September 26, 2011 05:39,
6 refactorings, tagged with rails
These two methods both seem...
if self.is_a?(Dog)
with_new_options do
$options << :Dog_videos
...
Ruby if/else with code duplication
by https://www.google.com/accounts/o8/id?id=AItOawldlqFajuby_15kAm_eqdxsKUOQpKvE99o,
September 30, 2011 07:02,
4 refactorings, tagged with rails short clean ruby
As you see, Event.queue sel...
def bad_books(good_book_ids) Book.all(:conditions => ["id NOT IN (?)", good_book_ids]) end ...
Ruby is there a smart way to usi...
Is there a better way to re...
class GroupByDate attr_reader :date, :id ...
Ruby Group by date
by coco-avisagsa-com.myopenid.com,
September 01, 2011 07:09,
1 refactoring
I'm using a dirty trick to ...
require 'rubygems' require 'facets' ...
Ruby getting the diff of two hashes
by https://www.google.com/accounts/o8/id?id=AItOawmHJ1ONaW6q8tTA21erxFUKoFCJsNY0QiE,
September 21, 2011 05:04,
1 refactoring
if I run a regular merge wi...
def find_factors(number) factors = [1,number] i = 2 ...
Ruby Find the factors of a number
by Aziz Light,
September 12, 2011 13:18,
1 refactoring
This little function will f...
#!/usr/bin/env ruby require 'rubygems' ...
Ruby automatic info plist versio...
I hacked up a script to aut...
.---.
| v*
.--------------.
...
Ruby Instance-level authorization
by dagobah.myopenid.com,
September 07, 2011 04:49,
No refactoring, tagged with rails, database, authorization, instance-level
Is this database structur...
class Job has_many :tasks ...
Ruby Convert SQL scopes to somet...
by KieranP,
September 07, 2011 15:46,
No refactoring, tagged with rails, postgres, named_scope, scopes
Using Rails 3.0.10, and Pos...
if @image.update_attributes params[:product_image]
if request.xhr?
render :json => { :status => 'success', :data => {:message => I18n.t('product_image.results.reordered')} }
...
Ruby DRY up a controller action
Any suggestions for DRYing ...
class IRC < TCPSocket
def cmd str
send "#{str}\r\n", 0
...
Ruby Calling methods from elsewhere
Is there any way to call cm...
def insertion_sort(list) #insertion sort @list = list index_a = 1 ...
Ruby Insertion Sort
by https://www.google.com/accounts/o8/id?id=AItOawmBGCnNiwxOiv77AwKGzLCYF1WOOMBZIdc,
August 11, 2011 23:42,
3 refactorings
Trying to write the easiest...
def randomize_case(string)
letters = string.split("")
...
Ruby Randomize case
Is there a better, shorter ...
def new
if current_user.has_credit_card_on_file?
redirect_to edit_user_billing_path, :notice => "We've detected that you already have a credit card on file, please edit the details below"
...
Ruby Feels like an easy refactor...
by https://www.google.com/accounts/o8/id?id=AItOawmRvMhcLFwL72d7b-9gx7YpThiobwkY3Co,
August 18, 2011 08:44,
2 refactorings, tagged with rails3 controller
I've got the method below w...
@visits_by_day_and_hour = visits.group_by{|day| day.created_at.strftime("%Y-%m-%d")}.map {|d, items| [d, items.group_by{|hour| hour.created_at.strftime("%H")}.map{|k,v| [k, v.length]}]}
Ruby Group array elements by day...
by https://www.google.com/accounts/o8/id?id=AItOawlsPHX5ps6aEa58SFp7fTjKFgMmK9Hi-Dg,
August 07, 2011 23:45,
2 refactorings, tagged with ruby, arrays, group_by, map array
Hi, I have a set of objects...
@stop_words = ["and", "on", "was", "in", "an", "it", "of", "a"]
words = "Here are 175 healthy recipes calibrated for males and females trying to lose fat.".split(/ /)
@stop_words.each { |a| if words.include?(a) then; words.delete(a) end;}
Ruby Array.include
by https://www.google.com/accounts/o8/id?id=AItOawkSg8scJklKELdYX2Rx5_OZpV3OPeKROdg,
August 11, 2011 14:10,
1 refactoring, tagged with Array include
this part of removing stop ...
scope :by_game, lambda{|game_id| where("team_game_id IN (SELECT id FROM team_games WHERE game_id = ?)", game_id)}
Ruby Bad Scope
by https://www.google.com/accounts/o8/id?id=AItOawkVKyrxjyHdaZjxtdWZH7QHlcULMtVNZ4I,
August 05, 2011 06:41,
1 refactoring, tagged with rails3 activerecord
I know this scope has an ea...
require 'set' class StatComputations ...
Ruby Mean Median in Ruby
by https://www.google.com/accounts/o8/id?id=AItOawl0nTuHS77YHoJ_YssSDUGitTHCLZVvgrA,
August 28, 2011 20:10,
1 refactoring, tagged with ruby, ruby1.9, mean, median
Here is the snippet of mean...
# Operators => Priority
OPERATORS={
'+' => 0,
...
Ruby Simple tokenizer
Takes a string and returns ...
def input ret = STDIN.gets.lstrip return ret.rstrip unless [?', ?"].include? ret[0] ...
Ruby User input with mutiple lines
by https://www.google.com/accounts/o8/id?id=AItOawnIPSSqMcibd_8s-QGdKZzB56unfy48gZc,
August 08, 2011 11:22,
No refactoring, tagged with STDIN, gets
This method will get the us...
FILE = File.join(File.dirname(__FILE__), '..', 'activity_exercise_sport.csv') WEIGHTS = [130, 155, 180, 205] ...
Ruby CSV to hash
The part where weight_calor...
Fairly new to ruby, wondere...