public
Last active

Class configuration using OpenStruct

  • Download Gist
config_example_open_struct.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
require 'ostruct'
 
module Awesome
def self.config
@config
end
 
def self.configure
yield(config)
end
 
class Configuration < OpenStruct ; end
 
@config = Configuration.new
end
 
Awesome.configure do |a|
a.magic_number = 3
end
 
puts Awesome.config.magic_number
# => 3
 
puts Awesome.config
# => #<Awesome::Configuration magic_number=3>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.