<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Bryan Helmkamp - Fluent interface for Ruby delegation Comments</title>
  <id>tag:www.brynary.com,2009:/2007/4/8/fluent-interface-for-ruby-delegation/comments</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://www.brynary.com/2007/4/8/fluent-interface-for-ruby-delegation/comments.xml" rel="self" type="application/atom+xml"/>
  <link href="/2007/4/8/fluent-interface-for-ruby-delegation" rel="alternate" type="text/html"/>
  <updated>2007-08-27T06:02:49Z</updated>
  <entry xml:base="http://www.brynary.com/">
    <author>
      <name>trans</name>
    </author>
    <id>tag:www.brynary.com,2007-04-08:44:91</id>
    <published>2007-06-21T01:14:31Z</published>
    <updated>2007-06-21T01:14:31Z</updated>
    <category term="Ruby"/>
    <link href="http://www.brynary.com/2007/4/8/fluent-interface-for-ruby-delegation" rel="alternate" type="text/html"/>
    <title>Comment on 'Fluent interface for Ruby delegation' by trans</title>
<content type="html">&lt;p&gt;Never heard the term &#8220;fluent&#8221; applied to this before. I&#8217;ve always heard it referred to as &#8220;magic dot&#8221;. But maybe &#8220;fluent&#8221; is better, but it take the &#8220;magic&#8221; out ;) One problem with this notation though is when the statements get long. One way to handle that of course is:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;delegate_reader(:line_items).
  to(:line_item_list)
delegate_reader(:total_value).
  as(:subtotal).to(:line_item_list)
delegate_writers(:first_name, :last_name).
  to(:owner)
delegate_accessors(:city, :state, :zip).
  with_prefix(:shipping).
  to(:shipping_address)&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;But I cant say I ever liked those trailing dots. Another means would be to also support a &#8220;fluent block&#8221; notation, so to speak:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;delegate_reader :line_items do
  to :line_item_list
end&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;delegate_reader :total_value do
  as :subtotal
  to :line_item_list
end&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;delegate_writers :first_name, :last_name do
  to :owner
end&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;delegate_accessors :city, :state, :zip do
  with_prefix :shipping
  to :shipping_address
end&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;T.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.brynary.com/">
    <author>
      <name>Bryan Helmkamp</name>
    </author>
    <id>tag:www.brynary.com,2007-04-08:44:64</id>
    <published>2007-04-25T03:18:50Z</published>
    <updated>2007-04-25T03:18:50Z</updated>
    <category term="Ruby"/>
    <link href="http://www.brynary.com/2007/4/8/fluent-interface-for-ruby-delegation" rel="alternate" type="text/html"/>
    <title>Comment on 'Fluent interface for Ruby delegation' by Bryan Helmkamp</title>
<content type="html">&lt;p&gt;Eric&#8212;Interesting idea. I worry about adding the extra complexity without too much of a gain in readability. Most of ActiveRecord reads quite naturally with its standard interface.&lt;/p&gt;


	&lt;p&gt;I wasn&#8217;t familiar with the concept of Higher Order Messaging. Thanks for that link.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.brynary.com/">
    <author>
      <name>Eric Allam</name>
    </author>
    <id>tag:www.brynary.com,2007-04-08:44:59</id>
    <published>2007-04-24T04:56:50Z</published>
    <updated>2007-04-24T04:56:50Z</updated>
    <category term="Ruby"/>
    <link href="http://www.brynary.com/2007/4/8/fluent-interface-for-ruby-delegation" rel="alternate" type="text/html"/>
    <title>Comment on 'Fluent interface for Ruby delegation' by Eric Allam</title>
<content type="html">&lt;p&gt;After working with rspec I am really starting to like fluent interfaces because of the increased readability and possibility for greater flexibility.  It reminds me of &lt;a href=&quot;http://nat.truemesh.com/archives/000535.html&quot;&gt;Higher Order Messaging&lt;/a&gt; which I was introduced to recently and haven&#8217;t fully digested.&lt;/p&gt;


	&lt;p&gt;What do you think about turning &lt;a href=&quot;http://www.last100meters.com/2007/4/24/activerecord-fluent-interface&quot;&gt;Active Record into a fluent interface?&lt;/a&gt;&lt;/p&gt;</content>  </entry>
</feed>
