Class: Module

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

Overview

taken from Jim Freeze’s excellent article “Creating DSLs with Ruby” www.artima.com/rubycs/articles/ruby_as_dsl.html

Instance Method Summary collapse

Instance Method Details

#dsl_accessor(*symbols) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/symian/support/dsl_helper.rb', line 5

def dsl_accessor(*symbols)
  symbols.each { |sym|
    class_eval %{
      def #{sym}(*val)
        if val.empty?
          @#{sym}
        else
          @#{sym} = val.size == 1 ? val[0] : val
        end
      end
    }
  }
end