Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / module / attr_internal.rb
1 class Module
2 # Declares an attribute reader backed by an internally-named instance variable.
3 def attr_internal_reader(*attrs)
4 attrs.each do |attr|
5 module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end"
6 end
7 end
8
9 # Declares an attribute writer backed by an internally-named instance variable.
10 def attr_internal_writer(*attrs)
11 attrs.each do |attr|
12 module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end"
13 end
14 end
15
16 # Declares an attribute reader and writer backed by an internally-named instance
17 # variable.
18 def attr_internal_accessor(*attrs)
19 attr_internal_reader(*attrs)
20 attr_internal_writer(*attrs)
21 end
22
23 alias_method :attr_internal, :attr_internal_accessor
24
25 private
26 mattr_accessor :attr_internal_naming_format
27 self.attr_internal_naming_format = '@_%s'
28
29 def attr_internal_ivar_name(attr)
30 attr_internal_naming_format % attr
31 end
32 end