Class: Module
- Defined in:
- lib/deployable/patch/attr_defaults.rb,
lib/deployable/patch/instance_class_variables.rb
Overview
Easier class variable access do the variable naming/symbol for you
Instance Method Summary collapse
- #__cvg(name) ⇒ Object
- #__cvs(name, value) ⇒ Object
-
#attr_accessor_default(options = {}) ⇒ Object
(also: #attr_default)
Provide accessors with a hash of defaults, and a default alias.
- #attr_initialize(method = nil) ⇒ Object
-
#attr_reader_default(options = {}) ⇒ Object
Provide readers with a hash of defaults.
-
#attr_writer_default(options = {}) ⇒ Object
Provide writers with a hash of defaults.
Instance Method Details
#__cvg(name) ⇒ Object
28 29 30 |
# File 'lib/deployable/patch/instance_class_variables.rb', line 28 def __cvg name class_variable_get :"@@#{name}" end |
#__cvs(name, value) ⇒ Object
32 33 34 |
# File 'lib/deployable/patch/instance_class_variables.rb', line 32 def __cvs name, value class_variable_set :"@@#{name}", value end |
#attr_accessor_default(options = {}) ⇒ Object Also known as: attr_default
Provide accessors with a hash of defaults, and a default alias
5 6 7 8 9 10 |
# File 'lib/deployable/patch/attr_defaults.rb', line 5 def attr_accessor_default = {} .each do |key, val| attr_accessor key unless instance_variable_defined? "@#{key}" instance_variable_set "@#{key}", val end end |
#attr_initialize(method = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 || = .delete_if do |key, val| instance_variable_defined? "@#{key}" or instance_variable_set "@#{key}", val end send method, end end |
#attr_reader_default(options = {}) ⇒ Object
Provide readers with a hash of defaults
14 15 16 17 18 19 |
# File 'lib/deployable/patch/attr_defaults.rb', line 14 def attr_reader_default = {} .each do |key, val| attr_reader key unless instance_variable_defined? "@#{key}" instance_variable_set "@#{key}", val end end |
#attr_writer_default(options = {}) ⇒ Object
Provide writers with a hash of defaults
22 23 24 25 26 27 |
# File 'lib/deployable/patch/attr_defaults.rb', line 22 def attr_writer_default = {} .each do |key, val| attr_writer key unless instance_variable_defined? "@#{key}" instance_variable_set "@#{key}", val end end |