Matz has just checked a change into the Ruby 1.9 tree to allow programming with fluent interfaces. The change is marked "experimental", but if it stays in the tree, we'll be able to write Ruby code like this:
puts "hello"
.upcase
.reverse
.slice(0) # => Prints "O"
(This is a silly example; Martin Fowler's page linked above has more compelling examples of this style of method chaining.)
We've always been able to do method chaining in Ruby, of course. What Matz's patch does is allow newlines in between the methods. This is tricky in languages like Ruby that don't require semicolons because newlines usually act as the statement terminators. So with this new modification a newline does not terminate a statement if the first non-space character on the following line is a period.
P.S. In case it hasn't been obvious from my recent postings on Ruby, I'm writing a book about Ruby. And I'm nearly done!




In case it hasn't been obvious from my recent postings on Ruby, I'm writing a book about Ruby.
It isn't obvious! Looking forward to it though. A general Ruby programming book or are there specific topics you'd be talking about?
Chu Yeow,
The book is called "The Ruby Programming Language", a general, but detailed and comprehensive book about the language itself.
David
hi david,
I've read 3/4 of your books and found them useful -- especially, the Javascript book.
How is your book gonna be different than the "PICK AXE" book ? I'd expect your book to be somewhat similar to the "javascript" RHINO book.
I'd also assume that your book would be more updated and probably ready for 1.9 than the "PICK AXE" book was.
Thank you,
BR,
~A