--0016364c716bd07a400461162330
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

>
>
> It would be used like:
>
>  class Bar
>   def foo
>     1
>   end
>
>   chain do
>     def foo
>       super + 1
>     end
>   end
> end
>

Just throwing this out [and I realize it's already been discussed a bit]...
It seems possible as long as you start with a module always...

class Class
 def chainable &block
  m  odule.new
  m.module_eval &block
  include m
 end
end

class A
 chainable do
   def abc
     print "in original abc"
   end
 end

 chainable do
    def abc
      print "in second abc"
      super
    end
 end

end

>> A.new.abc
in second abcin original abc


I will admit the inability to share a method from one class to another
[unrelated class] is surprising.  It seems that it is possible to move
methods from module to module and from module to class but not from class to
module or class to class.  Odd but not the end of the world.

I suppose for a more aggressive approach you could incorporate object2module
<tongue in cheek> [1].

Take care.

-
[1]
http://banisterfiend.wordpress.com/2008/12/18/object2module-converting-ruby-objects-to-modules/

--0016364c716bd07a400461162330
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div class="gmail_quote">
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div>
<div>
<div><br></div>
<div>It would be used like:</div>
<div><br></div>
<div>
<div>class Bar</div>
<div>&nbsp;&nbsp;def foo</div>
<div>&nbsp;&nbsp; &nbsp;1</div>
<div>&nbsp;&nbsp;end</div>
<div>&nbsp;&nbsp; &nbsp;</div>
<div>&nbsp;&nbsp;chain do</div>
<div>&nbsp;&nbsp; &nbsp;def foo</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp;super + 1</div>
<div>&nbsp;&nbsp; &nbsp;end</div>
<div>&nbsp;&nbsp;end</div>
<div>end</div></div></div></div></div></blockquote>
<div>&nbsp;</div>
<div>Just throwing this out [and I realize it&#39;s already&nbsp;been discussed a bit]...</div>
<div>It seems possible as long as you start with a module always...</div>
<div>&nbsp;</div>
<div>class Class<br>&nbsp;def chainable &amp;block<br>&nbsp; m = Module.new<br>&nbsp; m.module_eval &amp;block<br>&nbsp; include m<br>&nbsp;end<br>end</div>
<div><br>class A<br></div>
<div>&nbsp;chainable do<br>&nbsp;&nbsp; def abc<br>&nbsp;&nbsp;&nbsp;&nbsp;rint &quot;in original abc&quot;<br>&nbsp;&nbsp; end<br>&nbsp;end</div>
<div>&nbsp;</div>
<div>&nbsp;chainable do<br>&nbsp;&nbsp;&nbsp; def abc<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;in second abc&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;end</div>
<div>&nbsp;</div>
<div>end</div>
<div>&nbsp;</div>
<div>&gt;&gt; A.new.abc<br>in second abcin original abc</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>I will admit the inability to share a method from one class to anotherunrelated class] is surprising.&nbsp; It seems that it is possible to&nbsp;move methods from module to module and from module to class&nbsp;but not from class to module or class to class.&nbsp; Odd but not the end of the world.</div>

<div>&nbsp;</div>
<div>I suppose for a more aggressive approach you could incorporate object2module &lt;tongue in cheek&gt; [1].</div>
<div>&nbsp;</div>
<div>Take care.</div>
<div>&nbsp;</div>
<div>-=r</div>
<div>&nbsp;</div>
<div>[1] http://banisterfiend.wordpress.com/2008/12/18/object2module-converting-ruby-objects-to-modules/</div>
</div>

--0016364c716bd07a400461162330--