This file contains hidden or 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
def create_proc(cofactor) | |
proc = proc { |arg| arg * cofactor } | |
end | |
proc1 = create_proc(3) | |
proc2 = create_proc(5) | |
proc1.call(2) | |
=> 6 | |
proc2.call(2) |
This file contains hidden or 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 Mongoid::Document | |
include Mongoid::Timestamps::Created | |
field :language | |
has_many :profiles | |
scope :english, ->() do | |
where(:language => "english") |
This file contains hidden or 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
describe Account do | |
contex "given an empty account" do | |
subject { Account.new(0) } | |
context "when I put money there" do | |
before { subject.put_money(120) } | |
its(:amount) { should == 120 } | |
it { should_not be_empty } |
This file contains hidden or 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
qsort([Threshold | Tail]) -> | |
{ Left, Right } = split(Threshold, Tail), | |
qsort(Left) ++ [Threshold] ++ qsort(Right) | |
; | |
qsort([]) -> []. |
This file contains hidden or 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 "activerecord" | |
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => "test.sqlite" | |
class CategoriesMigration < ActiveRecord::Migration | |
def self.up | |
create_table :categories do |t| | |
t.string :name | |
t.string :type | |
end |
This file contains hidden or 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
var zombie = require("zombie"); | |
var assert = require("assert"); | |
// Load the page from localhost | |
zombie.visit("http://localhost:3000/", function (err, browser, status) { | |
// Fill email, password and submit form | |
browser. | |
fill("session[email]", "[email protected]"). | |
fill("session[password]", "123456"). |
This file contains hidden or 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
Genuine === genuine # => true | |
Genuine === proxy # => false |
This file contains hidden or 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
proxy = UltimateProxy.new(genuine) | |
proxy.class # => Genuine (despite this looks good...) | |
access_granted?(proxy) # => false (... we fail) |
This file contains hidden or 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
genuine = Genuine.new | |
access_granted?(genuine) # => true |
This file contains hidden or 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 Genuine; end; | |
def access_granted?(object) | |
case object | |
when Genuine | |
true | |
else | |
false | |
end | |
end |