This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example | |
def foo | |
def foo | |
:every_other_call | |
end | |
:first_call | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
roles do | |
role :admin, [:read, :write, :execute] | |
role :user do |r| | |
action :read | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original definition | |
class Whatever | |
def initialize | |
end | |
end | |
# Redefinition | |
class Whatever | |
alias_method :old_initialize, :initialize | |
def initialize(*args, &block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer