Module: Ritsu::Utility::Accessors::ClassMethods

Defined in:
lib/ritsu/utility/accessors.rb

Instance Method Summary collapse

Instance Method Details

#attr_method(*names) ⇒ Object



22
23
24
25
26
# File 'lib/ritsu/utility/accessors.rb', line 22

def attr_method(*names)
  names.each do |name|
    attr_method_single(name)
  end
end

#attr_method_single(name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ritsu/utility/accessors.rb', line 9

def attr_method_single(name)
  name = name.to_s
  module_eval <<-_RUBY
    def #{name}(*args)
      if args.length == 0
        @#{name} ||= nil
      elsif args.length == 1
        @#{name} = args[0]
      end
    end 
  _RUBY
end