Skip to content

Instantly share code, notes, and snippets.

View isaacsanders's full-sized avatar

Isaac Sanders isaacsanders

View GitHub Profile
@isaacsanders
isaacsanders / gist:1106558
Created July 26, 2011 11:48
Tim's Methods
require 'rspec'
require 'date'
describe "Tim's Methods" do
it "should be clear that Tim needs to get his ass back here" do
do_we_want_tim_back = TimsRep.new.do_we_like_him?
do_we_want_tim_back.should == true
end
end
@isaacsanders
isaacsanders / gist:1107078
Created July 26, 2011 15:53
Tim's Methods
require 'rspec'
require 'date'
describe "Tim's Methods:" do
let(:tim) { TimAffinity.new }
context "Tim is in India and" do
it "should be clear that Tim needs to get his ass back here" do
tim.do_we_want_him_back?.should be_true
@isaacsanders
isaacsanders / constant_class.rb
Created August 25, 2011 14:15
Keeping it Classy
# Foo is a constant that
Foo = Class.new
# We can define a superclass as an argument of the Class#new method,
# but the default is Object, and we are fine with that.
#=> Foo
Foo.class_eval do
def bar
:baz
end
@isaacsanders
isaacsanders / nested_def.rb
Created August 25, 2011 14:51
Def within a def
class Example
def foo
def foo
:every_other_call
end
:first_call
end
end
@isaacsanders
isaacsanders / reuse_user.rb
Created October 1, 2011 20:55
This is how you give your models easy role and action permissions.
require 'reuse'
class User
include ReUser
roles do
role(:admin) {|r| r.actions(:read, :write, :execute)}
role(:user) {|r| r.action(:read)}
default :user
end
@isaacsanders
isaacsanders / User.rb
Created October 2, 2011 03:21
For Jon Hogue
class User
include ReUser
roles do
role :god do |r|
r.action :manage_all
r.aciton :new_user_session
r.action :create_user_session
r.action :destroy_user_session
end
@isaacsanders
isaacsanders / List.rb
Created October 2, 2011 03:45 — forked from hoguej/User.rb
For Jon Hogue
roles do
role :admin, [:read, :write, :execute]
role :user do |r|
action :read
end
end
class MeetingDates
def initialize
@crb_dates = []
@jam_dates = []
calc_meeting_dates
end
def calc_meeting_dates
start_date = Date.today.beginning_of_year
(0..12).inject([]){|s, num| dates_for_month(start_date + num.months)}
# Original definition
class Whatever
def initialize
end
end
# Redefinition
class Whatever
alias_method :old_initialize, :initialize
def initialize(*args, &block)
@isaacsanders
isaacsanders / reuser.rb
Created October 23, 2011 05:14
ReUser Examples
# ReUser can be used in many ways
require 'reuser'
class User
# You always need to include ReUser to get the methods on the class
include ReUser
# You start your role definitions by passing a block to the `roles` method.
# Otherwise, it returns a hash of your roles
roles do