Class: OpenDSL

Inherits:
Module show all
Defined in:
lib/standard/facets/opendsl.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

Instance Method Summary collapse

Methods inherited from Module

#*, #+, #-, #Equitable, #abstract, #alias_class_method, #alias_method_chain, #alias_tester, #alias_validator, #all_instance_methods, #ancestor?, #anonymous?, #attr_class_accessor, #attr_class_reader, #attr_class_writer, #attr_setter, #attr_tester, #attr_validator, #can, #cattr, #cattr_accessor, #cattr_reader, #cattr_writer, #class_accessor, #class_def, #class_extend, #class_extensions, #class_inheritor, #class_reader, #class_writer, #copy_inheritor, #enclosure, #enclosures, #encname, #home, #homename, #housing, #include_as, #instance_function, #instance_method!, #instance_method_defined?, #integrate, #is, #is?, #lastname, #let, #mattr, #mattr_accessor, #mattr_reader, #mattr_writer, #memoize, #method_clash, #method_clash?, #method_space, #methodize, #module_def, #module_load, #module_require, #pathize, #preextend, #revise, #set, #singleton_method_defined?, #spacename, #to_obj, #wrap_method

Constructor Details

#initialize(&block) ⇒ OpenDSL

Returns a new instance of OpenDSL.



19
20
21
# File 'lib/standard/facets/opendsl.rb', line 19

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



24
25
26
27
28
29
30
# File 'lib/standard/facets/opendsl.rb', line 24

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