def randomize_case(string)
  string.split("").map { |c| (rand(2)) == 0 ? c.downcase : c.upcase  }.join('')
end

Ruby On Randomize case

by steved, August 22, 2011 13:20
B8ba61cc84ecb63c859435be28547dfb Talk
class Book

  class << self
...

Ruby On Padrino/Sinatra Multiple Te...

by steved, July 25, 2011 08:19

I'm a Rails / ActiveRecord ...

B8ba61cc84ecb63c859435be28547dfb Talk
def append
  "some random data" * 5
end

Ruby On append string in iterator

by steved, July 15, 2011 13:03
B8ba61cc84ecb63c859435be28547dfb Talk
class Game

  def sync_cores
...

Ruby On Tallying scores

by steved, June 26, 2011 16:32
B8ba61cc84ecb63c859435be28547dfb Talk
def rental_has_been_refunded?
  refunds.count(:transaction_sub_type => 'rental') > 0
end

Ruby On rental_has_been_refunded?

by steved, June 23, 2011 22:23

Using any? fetches the rows...

B8ba61cc84ecb63c859435be28547dfb Talk
a = ["a", "b", "c", "d"]
b = [1, 0, 0, 1]

...

Ruby On Reject and merge two arrays

by steved, May 06, 2011 09:03
B8ba61cc84ecb63c859435be28547dfb Talk
hash = { "user" => { "name" => "Tom", "message" => { "count" => 24, "last" => "2011-02-05" } } }
string_keys = "user/message/last"

...

Ruby On Finding a value in a Hash b...

by steved, May 02, 2011 11:38
B8ba61cc84ecb63c859435be28547dfb Talk
# controller
def create
  @lead = Lead.new(params[:lead])
...

Ruby On Best way to do this

by steved, April 28, 2011 11:22

Basic suggestion is to push...

B8ba61cc84ecb63c859435be28547dfb Talk
# Assume your Message class has columns user_id and message?
# create() takes a hash so presumambly:
params.inspect # => { "message" => {"message" => "msg from form"}, "other" => "params", ...}
...

Ruby On ---message: is appearing in...

by steved, April 03, 2011 23:02 Star_fullStar_fullStar_fullStar_fullStar_full
B8ba61cc84ecb63c859435be28547dfb Talk

Ruby On Rails Routing

by steved, March 27, 2011 18:57

Don't know how important RE...

B8ba61cc84ecb63c859435be28547dfb Talk
class Point
  attr_accessor :x, :y
  
...

Ruby On How to rewrite this method ...

by steved, March 07, 2011 00:39

Assuming you want to group ...

B8ba61cc84ecb63c859435be28547dfb Talk
def user_ubuntu?
  if `whoami` != "ubuntu"
    puts "You aren't logged in as ubuntu"
...

Ruby On script conditions

by steved, March 05, 2011 06:32

(Untested)

B8ba61cc84ecb63c859435be28547dfb Talk
name = unimportant_dasherize_method(@object.name)  # fix this to return nil rather than blank

array = [@object.id.to_s, name].compact
...

Ruby On Before/After String Logic

by steved, December 18, 2010 00:07 Star_fullStar_fullStar_fullStar_full
B8ba61cc84ecb63c859435be28547dfb Talk

Ruby On Page Title Display Helper

by steved, December 04, 2010 20:43

@Adam: "mutation of the sto...

B8ba61cc84ecb63c859435be28547dfb Talk
def display_title
  result = APP_CONFIG[:site][:title]
  result << " - #{@title}" if @title.present?
...

Ruby On Page Title Display Helper

by steved, December 02, 2010 18:01 Star_fullStar_fullStar_fullStar_fullStar_full

TimK: I think this site oft...

B8ba61cc84ecb63c859435be28547dfb Talk
# courses controller

  def index
...

Ruby On a simple list of categorize...

by steved, October 28, 2010 15:20

This doesn't look too bad. ...

B8ba61cc84ecb63c859435be28547dfb Talk
# assume you have added :month_year to DateTime::DATE_FORMATS

events_by_month_year = events.group_by { |e| e.start_date.to_s(:month_year) }

Ruby On AR help - return models gro...

by steved, September 23, 2010 17:23

Rails adds group_by to the ...

B8ba61cc84ecb63c859435be28547dfb Talk
module Menus

  class Main_Menu
...

Ruby On Help with module?!

by steved, August 26, 2010 14:15 Star_fullStar_fullStar_fullStar_fullStar_full
B8ba61cc84ecb63c859435be28547dfb Talk

Ruby On Sum of the Column

by steved, August 23, 2010 03:01

Adam: you're assuming Rails...

B8ba61cc84ecb63c859435be28547dfb Talk
sql = "select cart_id, sum(quantity) as sum_quantity from cart_items group by cart_id having sum_quantity > 6"
result = ActiveRecord::Base.connection.select_rows(sql)  #=>  [[1, 7], [3, 22]]
ids = result.map(&:first)  #=> [1, 3]

Ruby On Sum of the Column

by steved, August 21, 2010 16:58

This is a case where you ne...

B8ba61cc84ecb63c859435be28547dfb Talk
require 'uri'

size = 11
...

Ruby On Set value of key in uri

by steved, August 21, 2010 14:53

Not sure what you are tryin...

B8ba61cc84ecb63c859435be28547dfb Talk
def my_action    
  if @user.do_something_complicated(params)  # pass whatever the method need
    redirect_to home_path
...

Ruby On Redundant Else Clauses

by steved, August 06, 2010 05:55

Push all the logic in to th...

B8ba61cc84ecb63c859435be28547dfb Talk

Ruby On Help!! undefined method for...

by steved, July 28, 2010 15:33

You don't nee the .rb exten...

B8ba61cc84ecb63c859435be28547dfb Talk

Ruby On Help!! undefined method for...

by steved, July 28, 2010 05:45

It looks like your classes ...

B8ba61cc84ecb63c859435be28547dfb Talk

Ruby On Help!! undefined method for...

by steved, July 27, 2010 15:48

(Code as presented won't ru...

B8ba61cc84ecb63c859435be28547dfb Talk