Module: Wowr::Extensions::Class
- Included in:
- Class
- Defined in:
- lib/wowr/extensions.rb
Overview
Rails’s cattr_ things. activesupport/lib/active_support/core_ext/class Really quite handy. Thanks Reve’s Lisa Seelye
Instance Method Summary collapse
-
#cattr_accessor(*syms) ⇒ Object
:nodoc:.
-
#cattr_reader(*syms) ⇒ Object
:nodoc:.
-
#cattr_writer(*syms) ⇒ Object
:nodoc:.
-
#stringy(sym) ⇒ Object
:nodoc:.
Instance Method Details
#cattr_accessor(*syms) ⇒ Object
:nodoc:
46 47 48 49 |
# File 'lib/wowr/extensions.rb', line 46 def cattr_accessor(*syms) #:nodoc: cattr_reader(*syms) cattr_writer(*syms) end |
#cattr_reader(*syms) ⇒ Object
:nodoc:
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wowr/extensions.rb', line 8 def cattr_reader(*syms) #:nodoc: syms.flatten.each do |sym| next if sym.is_a?(Hash) class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} @@#{sym} = nil end def self.#{sym} @@#{sym} end def #{sym} @@#{sym} end EOS end end |
#cattr_writer(*syms) ⇒ Object
:nodoc:
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wowr/extensions.rb', line 27 def cattr_writer(*syms) #:nodoc: = syms.last.is_a?(Hash) ? syms.pop : {} syms.flatten.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} @@#{sym} = nil end def self.#{sym}=(obj) @@#{sym} = obj end #{" def #{sym}=(obj) @@#{sym} = obj end " unless [:instance_writer] == false } EOS end end |
#stringy(sym) ⇒ Object
:nodoc:
52 53 54 55 56 57 58 |
# File 'lib/wowr/extensions.rb', line 52 def stringy(sym) #:nodoc: class_eval(<<-EOS, __FILE__, __LINE__) def to_s @#{sym} end EOS end |