<p>I thought I&#39;d implement some missing members on the String class in order to get my feet wet and start to understand the software.&nbsp; I chose String.scan on the grounds that it was a fairly common function (between 20 and 30 references in the standard library) with straightforward semantics, but one which requires dealing with overloads and blocks. 
</p>
<p>There are basically four variations of this function:<br>String.scan &lt;string&gt;<br>String.scan &lt;regexp&gt;<br>String.scan &lt;string&gt;, &lt;block&gt;<br>String.scan &lt;regexp&gt;, &lt;block&gt;</p>
<p>I&#39;ve attempted to implement each of these, and believe that all but the last are correct.&nbsp; The &lt;string&gt; variations are implemented in two different flavors for both CLR strings and mutable strings.&nbsp; A patch can be found at 
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://hagenlocher.org/software/MutableString.scan.patch.txt" target="_blank">http://hagenlocher.org/software/MutableString.scan.patch.txt</a></p>
<p>The two issues I ran into are as follows:<br>1) The overload mechanism is picking the wrong method at runtime.&nbsp; Here are two of the function prototypes:</p>
<p>[RubyMethodAttribute(&quot;scan&quot;, RubyMethodAttributes.PublicInstance)]<br>public static List&lt;object&gt; Scan(MutableString/*!*/ self, MutableString/*!*/ searchStr)</p>
<div>[RubyMethodAttribute(&quot;scan&quot;, RubyMethodAttributes.PublicInstance)]<br>public static object Scan(CodeContext/*!*/ context, MutableString/*!*/ self, MutableString searchStr, BlockParam block)</div>
<div>&nbsp;</div>
<div>When I run from rbx.exe, I get the following:</div>
<div><font face="courier new,monospace">&gt;&gt;&gt; &quot;hello world&quot;.scan(&quot;l&quot;)<br>=&gt; [&quot;l&quot;, &quot;l&quot;, &quot;l&quot;]</font></div>
<div><font face="courier new,monospace">&gt;&gt;&gt; &quot;hello world&quot;.scan(&quot;l&quot;) {|x| print x}<br>=&gt; [&quot;l&quot;, &quot;l&quot;, &quot;l&quot;]<br></font></div>
<div>&nbsp;</div>
<div>In contrast, CRuby gives this:</div>
<div><font face="courier new,monospace">irb(main):001:0&gt; &quot;hello world&quot;.scan(&quot;l&quot;)<br>=&gt; [&quot;l&quot;, &quot;l&quot;, &quot;l&quot;]<br>irb(main):002:0&gt; &quot;hello world&quot;.scan(&quot;l&quot;) {|x| print x} 
<br>lll=&gt; &quot;hello world&quot;</font></div>
<div>&nbsp;</div>
<div>Am I doing something wrong, or is this a bug?&nbsp; (I have obviously updated Initializer.Generated.cs, or neither scan would have been found :).</div>
<div>&nbsp;</div>
<div>2) My implementation of String.scan &lt;regexp&gt;, &lt;block&gt; is incomplete.&nbsp; This function is defined to behave as follows:</div><font face="courier new,monospace">&nbsp;&nbsp; a.scan(/\w+/) {|w| print &quot;&lt;&lt;#{w}&gt;&gt; &quot; }&nbsp;
<br>&nbsp;&nbsp; a.scan(/(.)(.)/) {|x,y| print y, x }<br></font>
<div>&nbsp;</div>
<div>In other words, the number of parameters being passed to the block is equal to the number of groups defined in the regular expression -- or 1 if there are no groups defined.&nbsp; I haven&#39;t been able to find way to pass parameters&nbsp; or define a call site or that would support this.
</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>Finally, it&#39;s a bit annoying to rebuild Initializer.Generated.cs.&nbsp; Whenever you change a method signature, you have to manually delete the appropriate part of the old file in order to regenerate it, or you&#39;ll get an error.&nbsp; I&#39;ve made an empty version of that source file and a batch file that copies it on top of the previous version before rebuilding ClassInitGenerator.&nbsp; Assuming that the architecture is going to be here for a while, it would be nice if there were a target in the Rakefile that performed these steps.
</div>
<div>&nbsp;</div>
<div>After a few more hours of this, I may have to figure out how to do that myself. :)</div>
<div>&nbsp;</div>
<div>--</div>
<div>Curt Hagenlocher</div>
<div><a href="mailto:curt@hagenlocher.org">curt@hagenlocher.org</a></div>