Skip to content

Instantly share code, notes, and snippets.

@nesquena
Created August 23, 2012 07:01
Show Gist options
  • Save nesquena/3433669 to your computer and use it in GitHub Desktop.
Save nesquena/3433669 to your computer and use it in GitHub Desktop.
Ruby Source Article Snippets
# http://rubysource.com/polish-your-gems/
# Usage:
# Awesome.configure do |a|
# a.magic_number = 3
# end
module Awesome
class << self
attr_accessor :configuration
def config
self.configuration ||= Configuration.new
end
def configure
yield(config)
end
end
# The configuration object.
class Configuration < Hashie::Mash
end
end
module Something
def self.included(base)
base.extend ClassMethods
base.send(:include, InstanceMethods)
end
module ClassMethods
# ...
end
module InstanceMethods
# ...
end
end
class Search
class << self
def where(args)
Search.new(args)
end
end
def initialize(args)
@search_arguments = args
end
def where(args)
@search_arguments.merge!(args)
self
end
def each
results.each{|a| yield(a)}
end
def results
#Go and get some results!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment