- An
Object
is a set of instance variables and a pointer to a 'singleton class'. - Properties are looked up in the instance variables, methods are dispatched via the singleton class.
Module
is a subtype ofObject
. AModule
is a set of methods and an ordered list of zero-or-more 'parent' modules.- Module
A
becomes a parent of moduleB
viaB.include(A)
. - Method lookup works by doing a depth-first right-to-left search of a module tree.
Class
is a subtype ofModule
. AClass
is aModule
that can be instantiated.- A
Class
has only one 'superclass'. A class includes its superclass as its first parent module for the purposes of method dispatch. A class's singleton class includes the superclass's singleton class as its first parent. - The default superclass of all classes is
Object
.
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
gem 'activerecord', '3.2.12' | |
require 'active_record' | |
require "minitest/autorun" | |
require 'minitest/pride' | |
require 'logger' | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do |
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
if [[ $BUILD_STATUS == "success" ]] | |
then | |
export STATUS="success" | |
else | |
export STATUS="failure" | |
fi | |
curl "https://api.github.com/repos/justincampbell/my_repo/statuses/$GIT_COMMIT?access_token=abc123" \ | |
-H "Content-Type: application/json" \ | |
-X POST \ |
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 Product | |
include Mongoid::Document | |
field :price, type: Money | |
end | |
Money.class_eval do | |
# Converts an object of this instance into a database friendly value. | |
def mongoize |
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
-- show running queries (pre 9.2) | |
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
FROM pg_stat_activity | |
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- show running queries (9.2) | |
SELECT pid, age(clock_timestamp(), query_start), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
Locate the section for your github remote in the .git/config
file. It looks like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = [email protected]:joyent/node.git
Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:
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 'statsd' | |
$statsd = Statsd.new('your_host_here') | |
ActiveSupport::Notifications.subscribe /process_action.action_controller/ do |*args| | |
event = ActiveSupport::Notifications::Event.new(*args) | |
controller = event.payload[:controller] | |
action = event.payload[:action] | |
format = event.payload[:format] || "all" | |
format = "all" if format == "*/*" | |
status = event.payload[:status] |
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
#Model | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
response.should render_template(:index) | |
#Redirecting | |
response.should redirect_to(movies_path) |
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
--colour | |
-I app |
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
# Requirements: | |
# - The 'session' gem | |
# - A directory called 'rgen' and the files listed with copy, in the exact places listed | |
require 'session' | |
def run(command) | |
@session ||= Session::Shell.new | |
stdout, stderr = @session.execute command | |
puts stdout unless stdout.empty? | |
puts stderr unless stderr.empty? |