class Module
Monkeypatch in some methods to remove class setup boilerplate
Easier class variable access do the variable naming/symbol for you
Public Instance Methods
__cvg(name)
click to toggle source
# File lib/deployable/patch/instance_class_variables.rb, line 28 def __cvg name class_variable_get :"@@#{name}" end
__cvs(name, value)
click to toggle source
# File lib/deployable/patch/instance_class_variables.rb, line 32 def __cvs name, value class_variable_set :"@@#{name}", value end
attr_accessor_default(options = {})
click to toggle source
Provide accessors with a hash of defaults, and a default alias
# File lib/deployable/patch/attr_defaults.rb, line 5 def attr_accessor_default options = {} options.each do |key, val| attr_accessor key unless instance_variable_defined? "@#{key}" instance_variable_set "@#{key}", val end end
Also aliased as: attr_default
attr_initialize(method = nil)
click to toggle source
# File lib/deployable/patch/attr_defaults.rb, line 29 def attr_initialize method = nil # Create an `initialize` settings all the defaults # Allow another constructor to run `attr_initialize :some_method` # Would like to make this invisiable to initialize but # haven't come up with a cood way yet. raise 'initialize already defined 'if method_defined? :initialize define_method :initialize do |options| options_left = options.delete_if do |key, val| instance_variable_defined? "@#{key}" or instance_variable_set "@#{key}", val end send method, options_left end end
attr_reader_default(options = {})
click to toggle source
Provide readers with a hash of defaults
# File lib/deployable/patch/attr_defaults.rb, line 14 def attr_reader_default options = {} options.each do |key, val| attr_reader key unless instance_variable_defined? "@#{key}" instance_variable_set "@#{key}", val end end
attr_writer_default(options = {})
click to toggle source
Provide writers with a hash of defaults
# File lib/deployable/patch/attr_defaults.rb, line 22 def attr_writer_default options = {} options.each do |key, val| attr_writer key unless instance_variable_defined? "@#{key}" instance_variable_set "@#{key}", val end end