The documentation for Object#with suggests using it to initialize objects, but the examples it provides are not correct. They assume that #with returns the object, when it actually returns the result of the closure.
The first example works because StringBuilder#append serendipitously returns the object, and the closure returns the result of the last #append.
The second example does not work correctly, since the closure returns the result of the assignment to the lastName property.
Modifying the examples so that the closures explicitly return the object would make the documentation correct.