Class: OpenDSL

Inherits:
Module
  • Object
show all
Defined in:
lib/opendsl.rb,
lib/opendsl/version.rb

Overview

OpenDSL is a clever way to create a plugable free-form domain specific language.

Example = OpenDSL.new do
  size do
    100
  end
end

class Foo
  include Example
end

Foo.new.size  #=> 100

Constant Summary collapse

VERSION =

:erb: VERSION = “<%= version %>”

"1.1.1"

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ OpenDSL

Returns a new instance of OpenDSL.



21
22
23
# File 'lib/opendsl.rb', line 21

def initialize(&block)
  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(s, *a, &b) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/opendsl.rb', line 26

def method_missing(s, *a, &b)
  if block_given?
    define_method(s, &b)
  else
    super(s, *a, &b)
  end
end