Methods
Instance Public methods
# File activesupport/lib/active_support/configurable.rb, line 30 30: def config 31: @_config ||= if respond_to?(:superclass) && superclass.respond_to?(:config) 32: superclass.config.inheritable_copy 33: else 34: # create a new "anonymous" class that will host the compiled reader methods 35: Class.new(Configuration).new 36: end 37: end
Allows you to add shortcut so that you don’t have to refer to attribute through config. Also look at the example for config to contrast.
class User include ActiveSupport::Configurable config_accessor :allowed_access end user = User.new user.allowed_access = true user.allowed_access # => true
# File activesupport/lib/active_support/configurable.rb, line 55 55: def config_accessor(*names) 56: options = names.extract_options! 57: 58: names.each do |name| 59: reader, line = "def #{name}; config.#{name}; end", __LINE__ 60: writer, line = "def #{name}=(value); config.#{name} = value; end", __LINE__ 61: 62: singleton_class.class_eval reader, __FILE__, line 63: singleton_class.class_eval writer, __FILE__, line 64: class_eval reader, __FILE__, line unless options[:instance_reader] == false 65: class_eval writer, __FILE__, line unless options[:instance_writer] == false 66: end 67: end