<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:series="http://unfoldingneurons.com/"
		>
<channel>
	<title>Comments on: Customizing toString()</title>
	<atom:link href="http://blog.hexagonstar.com/customizing-tostring/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hexagonstar.com/customizing-tostring/</link>
	<description>&#34;Chaotic Neutral&#34;</description>
	<lastBuildDate>Thu, 11 Mar 2010 12:40:57 +0900</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: sascha</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-17900</link>
		<dc:creator>sascha</dc:creator>
		<pubDate>Thu, 21 Jan 2010 03:26:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-17900</guid>
		<description>@Rick check out the describeType function in the flash.utils package http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#describeType%28%29</description>
		<content:encoded><![CDATA[<p>@Rick check out the describeType function in the flash.utils package <a href="http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#describeType%28%29">http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#describeType%28%29</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick R</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-17891</link>
		<dc:creator>Rick R</dc:creator>
		<pubDate>Wed, 20 Jan 2010 19:50:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-17891</guid>
		<description>I&#039;m new to AS coming over from Java/Groovy. Does AS have some convenient reflection API? I&#039;d prefer my class toString introspect my class properties and dump them out as well.

In a groovy class I can just do:

   @Override
   String toString() {
     def props = this.properties
	String s = props[&quot;class&quot;].getName()+&quot;: &quot;
	//you don&#039;t want to see these in toString:
	props.remove(&quot;class&quot;)
	props.remove(&quot;metaClass&quot;) 
	return s + props
   }

The above will use reflection to dump out all my class properties MyCLass: foo = boo, doo = a, etc</description>
		<content:encoded><![CDATA[<p>I&#8217;m new to AS coming over from Java/Groovy. Does AS have some convenient reflection API? I&#8217;d prefer my class toString introspect my class properties and dump them out as well.</p>
<p>In a groovy class I can just do:</p>
<p>   @Override<br />
   String toString() {<br />
     def props = this.properties<br />
	String s = props["class"].getName()+&#8221;: &#8221;<br />
	//you don&#8217;t want to see these in toString:<br />
	props.remove(&#8220;class&#8221;)<br />
	props.remove(&#8220;metaClass&#8221;)<br />
	return s + props<br />
   }</p>
<p>The above will use reflection to dump out all my class properties MyCLass: foo = boo, doo = a, etc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: igor</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1791</link>
		<dc:creator>igor</dc:creator>
		<pubDate>Thu, 16 Oct 2008 01:39:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1791</guid>
		<description>Object.prototype.toString = function() {
  var r:String = &quot;[&quot; + getQualifiedClassName(this).match(&quot;[^:]*$&quot;)[0];
  if (this.name) 
    r += &quot; name =&quot;&quot; + this.name + &quot;&quot; &quot;;
  r += &quot;]&quot;
  return r;
}

Object.toString() is dynamic so it works for most of classes</description>
		<content:encoded><![CDATA[<p>Object.prototype.toString = function() {<br />
  var r:String = &#8220;[" + getQualifiedClassName(this).match("[^:]*$&#8221;)[0];<br />
  if (this.name)<br />
    r += &#8221; name =&#8221;" + this.name + &#8220;&#8221; &#8220;;<br />
  r += &#8220;]&#8221;<br />
  return r;<br />
}</p>
<p>Object.toString() is dynamic so it works for most of classes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sascha</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1584</link>
		<dc:creator>sascha</dc:creator>
		<pubDate>Sat, 04 Oct 2008 03:32:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1584</guid>
		<description>Thanks for the info tony! I wasn&#039;t sure but it&#039;s good to know that!</description>
		<content:encoded><![CDATA[<p>Thanks for the info tony! I wasn&#8217;t sure but it&#8217;s good to know that!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tony</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1574</link>
		<dc:creator>tony</dc:creator>
		<pubDate>Fri, 03 Oct 2008 20:11:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1574</guid>
		<description>You are right that regexps are more fun and also very handy to know. Anyway, I had to find out if there was a performance difference and ran a test. As expected, because the regular expressions are much more powerful than a plain search, they are also much slower. I ran each way in a tight loop 10,000 times and the regular expression method takes 120 times longer. If you are only doing a few dozen regex matches, no one would notice, but where performance is key and the matching is simple, avoid regex. They are mostly useful for very complex expressions that you cannot easily search for using simple methods. Anyway, great work on the toString override. I needed it and would never have come up with that myself.</description>
		<content:encoded><![CDATA[<p>You are right that regexps are more fun and also very handy to know. Anyway, I had to find out if there was a performance difference and ran a test. As expected, because the regular expressions are much more powerful than a plain search, they are also much slower. I ran each way in a tight loop 10,000 times and the regular expression method takes 120 times longer. If you are only doing a few dozen regex matches, no one would notice, but where performance is key and the matching is simple, avoid regex. They are mostly useful for very complex expressions that you cannot easily search for using simple methods. Anyway, great work on the toString override. I needed it and would never have come up with that myself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sascha</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1571</link>
		<dc:creator>sascha</dc:creator>
		<pubDate>Fri, 03 Oct 2008 17:10:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1571</guid>
		<description>hey tony. sure you could do that too with lastIndexOf as Joa said ... but where would be then fun in that?! ... i.e. I just wanted to make myself more familiar with RegExp&#039;s. Then again tostring methods aren&#039;t the kind of stuff that need to provide a lot of performance, but hey, choose what you like. :)</description>
		<content:encoded><![CDATA[<p>hey tony. sure you could do that too with lastIndexOf as Joa said &#8230; but where would be then fun in that?! &#8230; i.e. I just wanted to make myself more familiar with RegExp&#8217;s. Then again tostring methods aren&#8217;t the kind of stuff that need to provide a lot of performance, but hey, choose what you like. <img src='http://blog.hexagonstar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tony</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1570</link>
		<dc:creator>tony</dc:creator>
		<pubDate>Fri, 03 Oct 2008 16:18:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1570</guid>
		<description>Hey, that is some great and helpful stuff. Does just what I needed. I will put it to immediate use and thanks. Bythe way, I would think a search for text in a string would have to be faster than the regular expression, but I don&#039;t think performance-wise anyone will notice either way. Thanks again and take care.</description>
		<content:encoded><![CDATA[<p>Hey, that is some great and helpful stuff. Does just what I needed. I will put it to immediate use and thanks. Bythe way, I would think a search for text in a string would have to be faster than the regular expression, but I don&#8217;t think performance-wise anyone will notice either way. Thanks again and take care.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sascha</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1383</link>
		<dc:creator>sascha</dc:creator>
		<pubDate>Thu, 11 Sep 2008 12:53:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1383</guid>
		<description>Hi Joa, yes I had that method in mind too. the question is: what is more expensive? substring() or match()? I keep hearing from all sides that regExp&#039;s are more fast, powerful and generally being the next best thing to sliced bread. So I went with that. ;)</description>
		<content:encoded><![CDATA[<p>Hi Joa, yes I had that method in mind too. the question is: what is more expensive? substring() or match()? I keep hearing from all sides that regExp&#8217;s are more fast, powerful and generally being the next best thing to sliced bread. So I went with that. <img src='http://blog.hexagonstar.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joa Ebert</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1382</link>
		<dc:creator>Joa Ebert</dc:creator>
		<pubDate>Thu, 11 Sep 2008 12:46:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1382</guid>
		<description>Hey, besides the (expensive) RegExp you could also do this:

var name: String = getQualifiedClassName(obj);
name = name.substring( name.lastIndexOf( &#039;::&#039; ) + 2 );</description>
		<content:encoded><![CDATA[<p>Hey, besides the (expensive) RegExp you could also do this:</p>
<p>var name: String = getQualifiedClassName(obj);<br />
name = name.substring( name.lastIndexOf( &#8216;::&#8217; ) + 2 );</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sascha</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1371</link>
		<dc:creator>sascha</dc:creator>
		<pubDate>Mon, 08 Sep 2008 09:32:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1371</guid>
		<description>Thanks Steven! I improved the toString method a little more today ... I&#039;m using a base Class named BasicClass from that other classes can extend if they need toString. The BasicClass then gets the following:

&lt;pre&gt;public function toString(...args):String {
	var s:String = &quot;&quot;;
	for each (var i:String in args) s += &quot;, &quot; + i;
	return &quot;[&quot; + getQualifiedClassName(this).match(&quot;[^:]*$&quot;)[0]
	+ s + &quot;]&quot;;
}&lt;/pre&gt;

That way you could add any number of additional debug information comma-separated as an argument.
Sub-Classes then just need something like for example:

&lt;pre&gt;override public function toString(...args):String {
	return super.toString(&quot;path=&quot; + _path, &quot;size=&quot; + _size);
}&lt;/pre&gt;

So only the BasicClass needs to have the getQualifiedClassName... code in it.</description>
		<content:encoded><![CDATA[<p>Thanks Steven! I improved the toString method a little more today &#8230; I&#8217;m using a base Class named BasicClass from that other classes can extend if they need toString. The BasicClass then gets the following:</p>
<pre>public function toString(...args):String {
	var s:String = "";
	for each (var i:String in args) s += ", " + i;
	return "[" + getQualifiedClassName(this).match("[^:]*$")[0]
	+ s + "]";
}</pre>
<p>That way you could add any number of additional debug information comma-separated as an argument.<br />
Sub-Classes then just need something like for example:</p>
<pre>override public function toString(...args):String {
	return super.toString("path=" + _path, "size=" + _size);
}</pre>
<p>So only the BasicClass needs to have the getQualifiedClassName&#8230; code in it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven Sacks</title>
		<link>http://blog.hexagonstar.com/customizing-tostring/comment-page-1/#comment-1370</link>
		<dc:creator>Steven Sacks</dc:creator>
		<pubDate>Mon, 08 Sep 2008 08:09:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.hexagonstar.com/?p=640#comment-1370</guid>
		<description>That&#039;s some smart code right there. I&#039;m going to include it in the next release of the Gaia framework and really all my work from now on.  Thanks for the great tip!</description>
		<content:encoded><![CDATA[<p>That&#8217;s some smart code right there. I&#8217;m going to include it in the next release of the Gaia framework and really all my work from now on.  Thanks for the great tip!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
