Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created July 15, 2012 22:23
Show Gist options
  • Save leejarvis/3118918 to your computer and use it in GitHub Desktop.
Save leejarvis/3118918 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Simple configuration
require 'singleton'
class Foo
class Config < Struct.new(:first_name, :last_name)
include Singleton
end
def self.config
Config.instance
end
def self.configure
yield config
end
end
# A config plugin, perhaps?
module NameHelper
def full_name
[first_name, last_name].join(' ')
end
end
Foo.config.extend(NameHelper)
Foo.configure do |config|
config.first_name = "Something"
end
Foo.config.last_name = "Awesome"
p Foo.config.first_name #=> "Something"
p Foo.config.full_name #=> "Something Awesome"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment