Class: Class
- Inherits:
-
Object
- Object
- Class
- Defined in:
- lib/support/class_options.rb
Instance Method Summary collapse
Instance Method Details
#blockable_attr_accessor(sym) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/support/class_options.rb', line 9 def blockable_attr_accessor(sym) module_eval(<<-EVAL, __FILE__, __LINE__) def #{sym}(&block) if block_given? @#{sym} = block else @#{sym} end end def #{sym}=(value) @#{sym} = value end EVAL end |
#define_option(name, default = nil) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/support/class_options.rb', line 2 def define_option(name, default=nil) sym = name.to_sym cattr_reader(sym) cattr_writer(sym) send("#{name.to_s}=", default) end |