<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Mountain programming</title>
  <id>http://127.0.0.1</id>
  <updated>2010-12-14T00:00:00Z</updated>
  <author>
    <name>Daniel Vartanov</name>
  </author>
  <entry>
    <title>A trap of delegation</title>
    <link href="http://127.0.0.1/2011/04/06/a-trap-of-delegation/" rel="alternate"/>
    <id>http://127.0.0.1/2011/04/06/a-trap-of-delegation/</id>
    <published>2011-04-06T00:00:00Z</published>
    <updated>2011-04-06T00:00:00Z</updated>
    <author>
      <name>Daniel Vartanov</name>
    </author>
    <summary type="html">&lt;p&gt;Beware of proxy objects. Here is an edge case I fell into and want to warn you.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s consider an ultimate proxy class:&lt;/p&gt;

&lt;script src="https://gist.github.com/905490.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;p&gt;It delegates virtually everything to a given object. And one would
think (yeahl, including me) that we can use this proxy object
everywhere instead of the genuine object.&lt;/p&gt;

&lt;h2&gt;Counterexample&lt;/h2&gt;

&lt;p&gt;That&amp;rsquo;s not true and here is the trap:&lt;/p&gt;

&lt;script src="https://gist.github.com/905507.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;p&gt;A genuine object will pass this check:&lt;/p&gt;

&lt;script src="https://gist.github.com/905509.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;p&gt;But proxy object will &lt;em&gt;not&lt;/em&gt;:&lt;/p&gt;

&lt;script src="https://gist.github.com/905510.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;h2&gt;Why?&lt;/h2&gt;

&lt;p&gt;Because case internally uses &lt;code&gt;#===&lt;/code&gt; to determine if a given object
belongs to a certain &amp;ldquo;when-block&amp;rdquo;. Look:&lt;/p&gt;

&lt;script src="https://gist.github.com/905512.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;p&gt;It&amp;rsquo;s easier to track down in Rubinius:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Object::kind_of_p&lt;/code&gt; at &lt;a href="https://github.com/evanphx/rubinius/blob/master/vm/builtin/object.cpp#L428"&gt;vm/builtin/object.cpp:428&lt;/a&gt;&lt;br/&gt;
&lt;code&gt;Module::case_compare&lt;/code&gt; at &lt;a href="https://github.com/evanphx/rubinius/blob/master/vm/builtin/module.cpp#L66"&gt;vm/builtin/module.cpp:66&lt;/a&gt;&lt;br/&gt;
&amp;hellip;&lt;br/&gt;
&lt;code&gt;Module#===&lt;/code&gt; at &lt;a href="https://github.com/evanphx/rubinius/blob/master/kernel/common/module.rb#L572"&gt;kernel/common/module.rb:572&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You see? Not a single chance to have an influence on this process from
a Ruby level.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;Beware of proxy objects. Here is an edge case I fell into and want to warn you.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s consider an ultimate proxy class:&lt;/p&gt;

&lt;script src="https://gist.github.com/905490.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;p&gt;It delegates virtually everything to a given object. And one would
think (yeahl, including me) that we can use this proxy object
everywhere instead of the genuine object.&lt;/p&gt;

&lt;h2&gt;Counterexample&lt;/h2&gt;

&lt;p&gt;That&amp;rsquo;s not true and here is the trap:&lt;/p&gt;

&lt;script src="https://gist.github.com/905507.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;p&gt;A genuine object will pass this check:&lt;/p&gt;

&lt;script src="https://gist.github.com/905509.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;p&gt;But proxy object will &lt;em&gt;not&lt;/em&gt;:&lt;/p&gt;

&lt;script src="https://gist.github.com/905510.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;h2&gt;Why?&lt;/h2&gt;

&lt;p&gt;Because case internally uses &lt;code&gt;#===&lt;/code&gt; to determine if a given object
belongs to a certain &amp;ldquo;when-block&amp;rdquo;. Look:&lt;/p&gt;

&lt;script src="https://gist.github.com/905512.js?file=gistfile1.rb"&gt;&lt;/script&gt;


&lt;p&gt;It&amp;rsquo;s easier to track down in Rubinius:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Object::kind_of_p&lt;/code&gt; at &lt;a href="https://github.com/evanphx/rubinius/blob/master/vm/builtin/object.cpp#L428"&gt;vm/builtin/object.cpp:428&lt;/a&gt;&lt;br/&gt;
&lt;code&gt;Module::case_compare&lt;/code&gt; at &lt;a href="https://github.com/evanphx/rubinius/blob/master/vm/builtin/module.cpp#L66"&gt;vm/builtin/module.cpp:66&lt;/a&gt;&lt;br/&gt;
&amp;hellip;&lt;br/&gt;
&lt;code&gt;Module#===&lt;/code&gt; at &lt;a href="https://github.com/evanphx/rubinius/blob/master/kernel/common/module.rb#L572"&gt;kernel/common/module.rb:572&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You see? Not a single chance to have an influence on this process from
a Ruby level.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>git-sh and git-wtf together</title>
    <link href="http://127.0.0.1/2010/12/13/git-sh-and-git-wtf-together/" rel="alternate"/>
    <id>http://127.0.0.1/2010/12/13/git-sh-and-git-wtf-together/</id>
    <published>2010-12-13T00:00:00Z</published>
    <updated>2010-12-13T00:00:00Z</updated>
    <author>
      <name>Daniel Vartanov</name>
    </author>
    <summary type="html">&lt;p&gt;&lt;a href="http://github.com/rtomayko/git-sh"&gt;git-sh&lt;/a&gt; is awesome. As well as &lt;a href="http://github.com/DanielVartanov/git-wtf/blob/c22bb4f3ef50a80081240bb1aca3592910952e02/git-wtf"&gt;git-wtf&lt;/a&gt;. I bet most people are not aware of git-wtf, but they certainly should, cause it is an extremely convenient and useful tool when you are working with several branches and/or remotes. A little example of git-wtf output:&lt;/p&gt;

&lt;div style="background-color: black; color: #999999; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;
Local branch: heads/master
[x] in sync with remote

Remote branch: origin/master (git@github.com:account/project.git)
[x] in sync with local

Feature branches:
[x] ticket_827 is merged in
[ ] ticket_831 is NOT merged in (1 commit ahead; 18 commits behind)
- [dependencies] Depend on library X, version Y [bfda321]&lt;/div&gt;


&lt;p&gt;(see &lt;a href="http://github.com/michaelklishin/git-wtf"&gt;http://github.com/michaelklishin/git-wtf&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;span style="font-size: large;"&gt;The problem&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;If you are using git-sh, you have to type&lt;/p&gt;

&lt;div style="font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;b&gt;&lt;span style="background-color: orange;"&gt;branch&lt;/span&gt;&lt;span style="background-color: black; color: #cccccc;"&gt;!&lt;/span&gt;&lt;span style="background-color: black; color: #3d85c6;"&gt;repo&lt;/span&gt;&lt;span style="background-color: black; color: #cccccc;"&gt;&lt;span style="color: #999999;"&gt;&amp;gt; command git-wtf&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;


&lt;p&gt;which is long and annoying.&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;The solution&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;This post shows how to call &lt;i&gt;git-wtf&lt;/i&gt;&amp;nbsp; just by typing&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;span style="background-color: orange; font-family: 'Trebuchet MS', sans-serif;"&gt;branch&lt;/span&gt;&lt;span style="background-color: black; color: #cccccc; font-family: 'Trebuchet MS', sans-serif;"&gt;!&lt;/span&gt;&lt;span style="background-color: black; color: #3d85c6; font-family: 'Trebuchet MS', sans-serif;"&gt;repo&lt;/span&gt;&lt;span style="background-color: black; color: #999999; font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;gt; wtf&amp;nbsp;&lt;/span&gt; &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;in git-sh console.&lt;/p&gt;

&lt;p&gt;Clone the fork of git-wtf, which contains a pretty Makefile (I hope it will be merged into main repo soon):&lt;/p&gt;

&lt;div style="background-color: black; color: #999999; font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;b&gt;&lt;span style="color: #3d85c6;"&gt;$&lt;/span&gt; &lt;span style="color: #999999;"&gt;git clone http://github.com/DanielVartanov/git-wtf&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;


&lt;p&gt;Run &lt;i&gt;make&lt;/i&gt; to configure correspondent aliases for git and git-sh:&lt;/p&gt;

&lt;div style="background-color: black; color: #999999; font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;b&gt;&lt;span style="color: #3d85c6;"&gt;$&lt;/span&gt; make
git config --global alias.wtf '!git-wtf'
echo -e "\n# git-wtf\ngitalias wtf='git wtf'" &amp;gt;&amp;gt;

</summary>
    <content type="html">&lt;p&gt;&lt;a href="http://github.com/rtomayko/git-sh"&gt;git-sh&lt;/a&gt; is awesome. As well as &lt;a href="http://github.com/DanielVartanov/git-wtf/blob/c22bb4f3ef50a80081240bb1aca3592910952e02/git-wtf"&gt;git-wtf&lt;/a&gt;. I bet most people are not aware of git-wtf, but they certainly should, cause it is an extremely convenient and useful tool when you are working with several branches and/or remotes. A little example of git-wtf output:&lt;/p&gt;

&lt;div style="background-color: black; color: #999999; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;
Local branch: heads/master
[x] in sync with remote

Remote branch: origin/master (git@github.com:account/project.git)
[x] in sync with local

Feature branches:
[x] ticket_827 is merged in
[ ] ticket_831 is NOT merged in (1 commit ahead; 18 commits behind)
- [dependencies] Depend on library X, version Y [bfda321]&lt;/div&gt;


&lt;p&gt;(see &lt;a href="http://github.com/michaelklishin/git-wtf"&gt;http://github.com/michaelklishin/git-wtf&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;span style="font-size: large;"&gt;The problem&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;If you are using git-sh, you have to type&lt;/p&gt;

&lt;div style="font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;b&gt;&lt;span style="background-color: orange;"&gt;branch&lt;/span&gt;&lt;span style="background-color: black; color: #cccccc;"&gt;!&lt;/span&gt;&lt;span style="background-color: black; color: #3d85c6;"&gt;repo&lt;/span&gt;&lt;span style="background-color: black; color: #cccccc;"&gt;&lt;span style="color: #999999;"&gt;&amp;gt; command git-wtf&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;


&lt;p&gt;which is long and annoying.&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;The solution&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;This post shows how to call &lt;i&gt;git-wtf&lt;/i&gt;&amp;nbsp; just by typing&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;span style="background-color: orange; font-family: 'Trebuchet MS', sans-serif;"&gt;branch&lt;/span&gt;&lt;span style="background-color: black; color: #cccccc; font-family: 'Trebuchet MS', sans-serif;"&gt;!&lt;/span&gt;&lt;span style="background-color: black; color: #3d85c6; font-family: 'Trebuchet MS', sans-serif;"&gt;repo&lt;/span&gt;&lt;span style="background-color: black; color: #999999; font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;gt; wtf&amp;nbsp;&lt;/span&gt; &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;in git-sh console.&lt;/p&gt;

&lt;p&gt;Clone the fork of git-wtf, which contains a pretty Makefile (I hope it will be merged into main repo soon):&lt;/p&gt;

&lt;div style="background-color: black; color: #999999; font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;b&gt;&lt;span style="color: #3d85c6;"&gt;$&lt;/span&gt; &lt;span style="color: #999999;"&gt;git clone http://github.com/DanielVartanov/git-wtf&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;


&lt;p&gt;Run &lt;i&gt;make&lt;/i&gt; to configure correspondent aliases for git and git-sh:&lt;/p&gt;

&lt;div style="background-color: black; color: #999999; font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;b&gt;&lt;span style="color: #3d85c6;"&gt;$&lt;/span&gt; make
git config --global alias.wtf '!git-wtf'
echo -e "\n# git-wtf\ngitalias wtf='git wtf'" &amp;gt;&amp;gt; /.gitshrc&amp;nbsp;&lt;/b&gt;&lt;/div&gt;


&lt;p&gt;Run &lt;i&gt;make install&lt;/i&gt; if git-wtf script is not in PATH-directory already:&lt;/p&gt;

&lt;div style="background-color: black; color: #999999; font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;b&gt;&lt;span style="color: #3d85c6;"&gt;$&lt;/span&gt; sudo make install
install git-wtf /usr/local/bin&amp;nbsp;&lt;/b&gt;&lt;/div&gt;


&lt;p&gt;You can simply run &lt;i&gt;wtf&lt;/i&gt; command in git-sh console now:&lt;/p&gt;

&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/_PDm03OrXVe0/SsBmWGUIfEI/AAAAAAAAAmc/BRv0-Kd68PE/s1600-h/git-sh-wtf.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_PDm03OrXVe0/SsBmWGUIfEI/AAAAAAAAAmc/BRv0-Kd68PE/s400/git-sh-wtf.png" /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;p&gt;Enjoy :&amp;ndash;)&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Beyond the Ruby metaprogramming</title>
    <link href="http://127.0.0.1/2010/12/14/beyond-the-ruby-metaprogramming/" rel="alternate"/>
    <id>http://127.0.0.1/2010/12/14/beyond-the-ruby-metaprogramming/</id>
    <published>2010-12-14T00:00:00Z</published>
    <updated>2010-12-14T00:00:00Z</updated>
    <author>
      <name>Daniel Vartanov</name>
    </author>
    <summary type="html">&lt;p&gt;Here is a collection of very cool Ruby libs which extend Ruby&#8217;s metaprogramming and object model operation very much:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/object2module"&gt;object2module&lt;/a&gt; &#8212; Convert Classes and Objects to Modules so they can be extended/included&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/remix"&gt;remix&lt;/a&gt; &#8212; A library to give you total control over class and module ancestor chains&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/prepend"&gt;prepend&lt;/a&gt; &#8212; Prepends modules in front of a class; so method lookup starts with the module&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/local_eval"&gt;local_eval&lt;/a&gt; &#8212; Object#instance__eval without changing self&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/include_complete"&gt;include_complete&lt;/a&gt; &#8212; Use Module#include__complete to bring in singleton classes from modules&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rkh/mixico"&gt;mixico&lt;/a&gt; &amp;mdash; Disable and re-enable mixins&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;Here is a collection of very cool Ruby libs which extend Ruby&#8217;s metaprogramming and object model operation very much:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/object2module"&gt;object2module&lt;/a&gt; &#8212; Convert Classes and Objects to Modules so they can be extended/included&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/remix"&gt;remix&lt;/a&gt; &#8212; A library to give you total control over class and module ancestor chains&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/prepend"&gt;prepend&lt;/a&gt; &#8212; Prepends modules in front of a class; so method lookup starts with the module&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/local_eval"&gt;local_eval&lt;/a&gt; &#8212; Object#instance__eval without changing self&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/banister/include_complete"&gt;include_complete&lt;/a&gt; &#8212; Use Module#include__complete to bring in singleton classes from modules&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rkh/mixico"&gt;mixico&lt;/a&gt; &amp;mdash; Disable and re-enable mixins&lt;/p&gt;
</content>
  </entry>
</feed>

