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
# Each of the following classes visit the objects, doing something different | |
# each time. | |
class CarElementPrintVisitor | |
def visit(subject) | |
puts "Visiting: %s" % subject.class.to_s | |
end | |
end | |
class CarElementDoVisitor | |
def visit(subject) |
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 Car < CarElement | |
def initialize | |
# Here we build an array of objects that will be visited. This can be done | |
# after initialize as well; it just needs to be built before calling 'accept'. | |
@elements = [] | |
@elements << Wheel.new("front left") | |
@elements << Wheel.new("front right") | |
@elements << Wheel.new("back left") | |
@elements << Wheel.new("back right") | |
@elements << Body.new |
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 CarElement | |
# force subclasses to override the accept method | |
def accept(visitor) | |
raise NotImpelementedError.new | |
end | |
end | |
class Wheel < CarElement | |
include Visitable # now we have the 'accept' method |
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
module Visitable | |
# Accept a visitor object. This will be visited, meaning its 'visit' method | |
# will be invoked | |
def accept(visitor) | |
visitor.visit(self) | |
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 Body < CarElement | |
include Visitable # now we have the 'accept' method | |
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
input { | |
gelf { type => 'gelf' } | |
} | |
output { | |
mongodb { | |
host => '127.0.0.1' | |
database => 'rails_logs' | |
collection => "%{facility}" | |
} | |
} |
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
it "should allow only strings that include the letter 'a'" do | |
StringAllower.allowed?('a bed').should == true | |
StringAllower.allowed?('my bed').should == false | |
StringAllower.allowed?('single bed').should == false | |
StringAllower.allowed?('a single bed').should == true | |
StringAllower.allowed?('some car').should == true | |
StringAllower.allowed?('some motorcycle').should == false | |
.... | |
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
authorized_human = (is_human == true && is_authorized == true) | |
invalid_or_errd = (invalid_data == true || error_occurred == true) | |
if(response && authorized_human && !invalid_or_errd | |
# do something insane | |
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
# the eight element in the fibonacci sequence is 21 | |
n = 8 | |
five_square = Math.sqrt(5) | |
(((1 + five_square)**n) - ((1 - five_square)**n)) / (2**n * five_square) |
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
alias gb='git branch' | |
alias gc='git commit -v' | |
alias gd='git diff' | |
alias gg='git grep -n' | |
alias gl='git pull' | |
alias gm='git merge' | |
alias gp='git push' | |
alias gr='git reset' | |
alias gap='git add -p' | |
alias gca='git commit -a -v' |
NewerOlder