Skip to content

Instantly share code, notes, and snippets.

View danielcooper's full-sized avatar

Daniel Cooper danielcooper

View GitHub Profile
{% assign name = 'bar' %}
{% if name == 'bar' %}
{{name}}
{%endif%}
source = context[@attributes['source']] if context.has_key? @attributes['source']
@danielcooper
danielcooper / gist:3332095
Created August 12, 2012 14:35
chaining example
class Search
class << self
def where(args)
Search.new(args)
end
end
def initialize(args)
@search_arguments = args
end
module HTTParty
def self.included(base)
base.extend ClassMethods
#snip
base.instance_variable_set("@default_options", {})
end
end
@danielcooper
danielcooper / gist:3332088
Created August 12, 2012 14:33
Config block example
#Usage:
# Awesome.configure do |a|
# a.magic_number = 3
# end
module Awesome
class << self
attr_accessor :configuration
def config
self.configuration ||= Configuration.new
@danielcooper
danielcooper / gist:3332092
Created August 12, 2012 14:34
Chaining example
##AR 2
Person.find(:all, :conditions => {:name => "Joe", :is_admin => true}, :limit => 10)
##=> Array
#AR 3
Person.where(:name => 'joe', :is_admin => true).limit(10)
##=> ActiveRecord::Relation
@danielcooper
danielcooper / gist:3332108
Created August 12, 2012 14:36
Party hard
class Thingy
include HTTParty
end
@danielcooper
danielcooper / gist:3430097
Created August 22, 2012 22:31
Bit of cache config
backend facebookforcats {
.host = "localhost";
.port = "3000";
}
class Code
def initialize(person)
@person = person
end
def make_bugs
"#{@person.name} does some typing"
end
end
module BugMakingSupport
def make_bugs
"#{@person.name} does some typing"
end
end
class Developer < Employee
include BugMakingSupport
end