Skip to content

Instantly share code, notes, and snippets.

Avatar

Isaac Sanders isaacsanders

View GitHub Profile
View gist:1106558
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
View gist:1107078
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
View constant_class.rb
# 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
View nested_def.rb
class Example
def foo
def foo
:every_other_call
end
:first_call
end
end
@isaacsanders
isaacsanders / reuse_user.rb
Created Oct 1, 2011
This is how you give your models easy role and action permissions.
View reuse_user.rb
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
View User.rb
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 Oct 2, 2011 — forked from hoguej/User.rb
For Jon Hogue
View List.rb
roles do
role :admin, [:read, :write, :execute]
role :user do |r|
action :read
end
end
View gist:1297210
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)}
View gist:1306234
# Original definition
class Whatever
def initialize
end
end
# Redefinition
class Whatever
alias_method :old_initialize, :initialize
def initialize(*args, &block)
View reuser.rb
# 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