instiki/vendor/rails/activesupport/lib/active_support/core_ext/module/attr_internal.rb

33 lines
934 B
Ruby
Raw Normal View History

2007-02-10 00:12:31 +01:00
class Module
2008-06-02 08:35:38 +02:00
# Declares an attribute reader backed by an internally-named instance variable.
2007-02-10 00:12:31 +01:00
def attr_internal_reader(*attrs)
attrs.each do |attr|
module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end"
end
end
2008-06-02 08:35:38 +02:00
# Declares an attribute writer backed by an internally-named instance variable.
2007-02-10 00:12:31 +01:00
def attr_internal_writer(*attrs)
attrs.each do |attr|
module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end"
end
end
2008-06-02 08:35:38 +02:00
# Declares an attribute reader and writer backed by an internally-named instance
# variable.
2007-02-10 00:12:31 +01:00
def attr_internal_accessor(*attrs)
attr_internal_reader(*attrs)
attr_internal_writer(*attrs)
end
alias_method :attr_internal, :attr_internal_accessor
private
mattr_accessor :attr_internal_naming_format
self.attr_internal_naming_format = '@_%s'
def attr_internal_ivar_name(attr)
attr_internal_naming_format % attr
end
end