Created
August 23, 2012 07:01
-
-
Save nesquena/3433669 to your computer and use it in GitHub Desktop.
Ruby Source Article Snippets
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
# 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 |
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
module Something | |
def self.included(base) | |
base.extend ClassMethods | |
base.send(:include, InstanceMethods) | |
end | |
module ClassMethods | |
# ... | |
end | |
module InstanceMethods | |
# ... | |
end | |
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
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