Skip to content

Instantly share code, notes, and snippets.

# Original Post: http://pastie.textmate.org/143799
# Author Karmen Blake
#RUBYISMS
a = b.foo
if a.empty?
a = b.bar
else
a.reverse!
stupid ruby tricks
Posted by Nick Quaranto
# Over the past few months of slinging Ruby here at Thoughtbot, I’ve picked up quite a
# few stupid ruby tricks smart ruby techniques that really help out your code.
# If you’ve got your own, feel free to leave a comment.
# Destructuring yielded arrays
def touch_down
##### I need to be able to eager load the notes element on the lesson element. Figured the best way to do it was through an
##### association.
##############
# doesn't work . . . conditions on associations don't take lambda's
class Note < ActiveRecord::Base
belongs_to :notable, :polymorphic => true
end
class Lesson < ActiveRecord::Base
# Everything you need to do to get started with Rails 2.3.8
#
# As of June 14th, 2010 @ 2:30 p.m. MST
#
# This gist now features instructions to get Rails 3 up and running with:
# - Ruby 1.8.7-p174
# - Bundler 0.9.26
# - Cucumber 0.8.0
# - Rspec 1.3.0 + Rspec-Rails 1.3.2
# - RVM
 → gem install memcache
Building native extensions. This could take a while...
ERROR: Error installing memcache:
ERROR: Failed to build gem native extension.
/Users/bushymark/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
Building libmemcached.
tar xzf libmemcached-0.38.tar.gz 2>&1
env CFLAGS='-fPIC' ./configure --prefix=/Users/bushymark/.rvm/gems/ruby-1.9.2-p0@rails3/gems/memcache-1.2.13/ext --without-memcached --disable-shared --disable-utils --disable-dependency-tracking 2>&1
checking build system type... x86_64-apple-darwin10.4.0
@bushymark
bushymark / Routes.rb
Created November 2, 2010 02:11
Output from Controller specs
namespace :discussions do
resources :posts, :only => [:show, :create, :update, :destroy] do
resources :replies, :only => :create
resources :flags, :only => [:create, :destroy]
resources :votes, :only => [:create, :destroy]
resources :favorites, :only => [:create, :destroy]
end
end
# same result on flags, votes, favorites, or replies
@bushymark
bushymark / Gemfile
Created April 26, 2012 02:34
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin