The Builder

Build à la carte rules and rule books without a dedicated class.

The Builder

Builder@rulebox is a singleton that lets you create rules and rule books on the fly, without writing a dedicated class that extends RuleBook. It's handy for dynamic or à la carte rules assembled at runtime.

builder = getInstance( "Builder@rulebox" )

myRuleBook = builder.rulebook( "My RuleBook" )
	.addRule(
		builder.rule()
			.then( ( facts ) => println( "Hello " ) )
	)
	.addRule(
		builder.rule()
			.then( ( facts ) => println( "World " ) )
	)

myRuleBook.run()
MethodReturnsDescription
rulebook( name="" )RuleBookCreates a new RuleBook, optionally named
rule( name )RuleCreates a new standalone Rule, optionally named

Since builder.rulebook() returns a normal RuleBook instance, every method described in The RuleBook DSL and Facts & Results - given(), withDefaultResult(), addRule(), run() - is available on it, exactly as it would be on a hand-written RuleBook subclass.

Edit this page Download Markdown Last updated Sep 17, 2026, 7:29:54 PM