Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/support/class_options.rb

Instance Method Summary collapse

Instance Method Details

#attr_accessor_with_default(sym, default = nil, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/support/class_options.rb', line 26

def attr_accessor_with_default(sym, default = nil, &block)
  raise 'Default value or block required' unless !default.nil? || block
  define_method(sym, block_given? ? block : Proc.new { default })
  module_eval("    def \#{sym}=(value)\n      class << self; attr_reader :\#{sym} end\n      @\#{sym} = value\n    end\n  EVAL\nend\n", __FILE__, __LINE__)