This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.
Configuration is often the first thing users interact with in your gem. It’s also the part most gem authors spend the least time thinking about—which explains a lot. This post covers the patterns you’ll encounter and implement, ordered from the simplest to the most involved. Module accessors The simplest possible approach. You expose a few attributes on your gem’s main module and call it a day.…
Configuration is often the first thing users interact with in your gem. It’s also the part most gem authors spend the least time thinking about—which explains a lot. This post covers the patterns you’ll encounter and implement, ordered from the simplest to the most involved. Module accessors The simplest possible approach. You expose a few attributes on your gem’s main module and call it a day. module MyGem class << self attr_accessor :api_key, :timeout, :debug end self.timeout = 30 self.debug = false end MyGem.api_key = "sk-123" MyGem.timeout = 60 puts "api_key: #{MyGem.api_key}" puts "timeout: #{MyGem.timeout}" puts "debug: #{MyGem.debug}" Run Reset...Read on /posts/gem-configuration-patterns/ ↗
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.