Module: ScopedAttrAccessor

Included in:
Object
Defined in:
lib/scoped_attr_accessor.rb,
lib/scoped_attr_accessor/version.rb

Overview

This module adds scoped accessor methods to a Ruby Class. For example:

class Foo
  extend ScopedAttrAccessor
  private_attr_reader :thing1, :thing2, :thing3
  protected_attr_writer :counter
  protected_attr_accessor :flagbag
end

They work exactly the same as the regular ruby attr_accessor methods, except they are placed in the appropriate public or private scope as desired.

Constant Summary collapse

VERSION =
"1.0.2"

Instance Method Summary collapse

Instance Method Details

#private_attr_accessor(*names) ⇒ Object



27
28
29
30
# File 'lib/scoped_attr_accessor.rb', line 27

def private_attr_accessor(*names)
  private_attr_reader(*names)
  private_attr_writer(*names)
end

#private_attr_reader(*names) ⇒ Object



17
18
19
20
# File 'lib/scoped_attr_accessor.rb', line 17

def private_attr_reader(*names)
  attr_reader(*names)
  names.each {|name| private name}
end

#private_attr_writer(*names) ⇒ Object



22
23
24
25
# File 'lib/scoped_attr_accessor.rb', line 22

def private_attr_writer(*names)
  attr_writer(*names)
  names.each {|name| private "#{name}=" }
end

#protected_attr_accessor(*names) ⇒ Object



42
43
44
45
# File 'lib/scoped_attr_accessor.rb', line 42

def protected_attr_accessor(*names)
  protected_attr_reader(*names)
  protected_attr_writer(*names)
end

#protected_attr_reader(*names) ⇒ Object



32
33
34
35
# File 'lib/scoped_attr_accessor.rb', line 32

def protected_attr_reader(*names)
  attr_reader(*names)
  names.each {|name| protected name}
end

#protected_attr_writer(*names) ⇒ Object



37
38
39
40
# File 'lib/scoped_attr_accessor.rb', line 37

def protected_attr_writer(*names)
  attr_writer(*names)
  names.each {|name| protected "#{name}=" }
end