lib/jrubyfx/dsl.rb
# This is the heart of the DSL. When a method is missing and the name of the
# method is in the NAME_TO_CLASSES mapping, it calls JRubyFX.build with the
# Java class. This means that instead of saying
#   build(JavaClass, hash) { ... }
# you can say
#   java_class(hash) { ... }
#
# Another major portion of the DSL is the ability to implicitly add new
# created components to their parent on construction.  There are a few
# places where this is undesirable.  In order to prevent implicit
# construction you can add a '!' on the end:
#   circle!(30)
# This will construct a Circle but it will not add it into its parent
# container.  This is useful for specifying clipping regions in particular.
#
This is the heart of the DSL. When a method is missing and the name of the
method is in the NAME_TO_CLASSES mapping, it calls JRubyFX.build with the
Java class. This means that instead of saying
build(JavaClass, hash) { ... }
you can say
java_class(hash) { ...

Another major portion of the DSL is the ability to implicitly add new
created components to their parent on construction.  There are a few
places where this is undesirable.  In order to prevent implicit
construction you can add a '!' on the end:
circle!(30)
This will construct a Circle but it will not add it into its parent
container.  This is useful for specifying clipping regions in particular.
This is the heart of the DSL . When a method is missing and the name of the method is in the NAME_TO_CLASSES mapping it calls JRubyFX . build with the Java class . This means that instead of saying build ( JavaClass hash ) { ... } you can say java_class ( hash ) { ... Another major portion of the DSL is the ability to implicitly add new created components to their parent on construction . There are a few places where this is undesirable . In order to prevent implicit construction you can add a ' ! ' on the end : circle! ( 30 ) This will construct a Circle but it will not add it into its parent container . This is useful for specifying clipping regions in particular .
def method_missing(name, *args, &block)
      fixed_name = name.to_s.gsub(/!$/, '')
      clazz = NAME_TO_CLASSES[fixed_name]
      unless clazz
        clazz = NAME_TO_CLASS_NAME[fixed_name]
        clazz = (NAME_TO_CLASSES[fixed_name] = clazz.constantize_by("::")) if clazz
      end
      unless clazz
        @supers = {} unless @supers
        @supers[name] = 0 unless @supers.has_key?(name)
        @supers[name] += 1
        if @supers[name] > 3
          raise "Whoa! method_missing caught infinite loop. Trying to run #{name}(#{args.inspect}) failed. Method not found."
        end
        res = super
        @supers[name] -= 1
        return res
      end
      build(clazz, *args, &block)
    end
def method_missing ( name , * args , & block ) fixed_name = name . to_s . gsub ( / !$ / , '' ) clazz = NAME_TO_CLASSES [ fixed_name ] unless clazz clazz = NAME_TO_CLASS_NAME [ fixed_name ] clazz = ( NAME_TO_CLASSES [ fixed_name ] = clazz . constantize_by ( "::" ) ) if clazz end unless clazz @supers = { } unless @supers @supers [ name ] = 0 unless @supers . has_key? ( name ) @supers [ name ] += 1 if @supers [ name ] > 3 raise "Whoa! method_missing caught infinite loop. Trying to run #{name}(#{args.inspect}) failed. Method not found." end res = super @supers [ name ] -= 1 return res end build ( clazz , * args , & block ) end
This is the heart of the DSL.
This is the heart of the DSL .
name
<not_specific>
args
<not_specific>
block
<not_specific>