Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

12. Meta-Programming > Writing Fluent Interfaces

Writing Fluent Interfaces

Here is a short example of using Ruby’s meta-programming support to write a fluent interface that goes beyond Java’s capabilities. Obviously, an entire book could be written about this subject—this will just give you a taste. This code works on any version of Ruby, including the Java platform port, JRuby.

You want to write a fluent interface that represents recipes. It should allow developers to write the ingredients for the recipes in what looks like a data format, but underneath it should build a nutrition profile. The ability to encapsulate the actual behavior of code is one of the advantages of fluent interfaces. Here is the target syntax:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint