That works, but it has the following disadvantages over the method I
described:
If you use ActiveSupport::Configurable you are tied to using
activesupport/Rails. Many times you want to write the Gem so that it
isn’t
Rails-specific and want to limit dependencies.
I know Rails uses the “pass the config into the block thing”, but it
isn’t as DRY as not typing “config.” before each parameter.
By defining the attr_accessors, you limit the chance that a user will
mistype/misspell a variable.
The way you described allows the user to define config parameters
with
procs and lambdas, but the way I describe allows the user to define
“config
parameters” as procs, lambdas, and methods, i.e. the user can actually
just
define a variable as:
def some_variable_name
some really involved implementation here, even refactored into
Just as an update, I had bugs in the previous code provided and fixed
with
help from Jess Gabriel y Galn and Calvin B. on the list in this post: http://www.ruby-forum.com/topic/4406183
module MyModule
class << self
attr_accessor :debug, :proc_or_lambda, :some_array, :some_hash,
:time
def configure(&blk); class_eval(&blk); end
end
end