Class: Module

Inherits:
Object show all
Defined in:
lib/eymiha.rb

Overview

Provides class attribute setters and getters, for mondo convenience

Instance Method Summary collapse

Instance Method Details

#class_attr_accessor(*kattrs) ⇒ Object

Creates a reader and writer for the given class variables



52
53
54
55
# File 'lib/eymiha.rb', line 52

def class_attr_accessor(*kattrs)
  class_attr_reader(*kattrs)
  class_attr_writer(*kattrs)
end

#class_attr_reader(*kattrs) ⇒ Object

Creates a reader for the given class variables



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/eymiha.rb', line 58

def class_attr_reader(*kattrs)
  kattrs.each { |kattr|
    ka = kattr.to_s
    reader = <<EOF
def self.#{ka}
@@#{ka}
end
@@#{ka} = nil
EOF
    self.module_eval reader
  }
end

#class_attr_writer(*kattrs) ⇒ Object

Creates a writer for the given class variables



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/eymiha.rb', line 72

def class_attr_writer(*kattrs)
  kattrs.each { |kattr|
    ka = kattr.to_s
    writer = <<EOF
def self.#{ka}=(#{ka})
@@#{ka} = #{ka}
end
EOF
    self.module_eval writer
  }
end