<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Real Class</title>
	<link>http://www.klankboomklang.com/2007/09/28/real-class/</link>
	<description>Ruby and otherwise by Patrick Farley</description>
	<pubDate>Wed, 08 Sep 2010 20:34:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>

	<item>
		<title>By: pfarley</title>
		<link>http://www.klankboomklang.com/2007/09/28/real-class/#comment-78</link>
		<dc:creator>pfarley</dc:creator>
		<pubDate>Wed, 03 Oct 2007 03:36:57 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/09/28/real-class/#comment-78</guid>
		<description>Hi Ryan,

I'm afraid your statement, "EVERY object has a singleton class implicitly, no matter what." is not accurate.  Objects have a singleton class created implicitly the first time the singleton class is accessed, but if it is never accessed, there is no singleton class.  Hence the equality issue.  More specifically, the singleton class for an object is created the first time rb_singleton_class (line 854 in class.c) is called.  I used RubyInline to write an example that shows this in action:

require "inline"
class Object
  inline do &#124;builder&#124;
    builder.c "
      VALUE klass(VALUE object) {
        return RBASIC(object)-&gt;klass;
      }"
  end
end

class Point; end

point = Point.new

klass(point).object_id
#=&gt; 3080598
klass(Point.new).object_id
#=&gt; 3080598
def point.spin; end
klass(point).object_id 
#=&gt; 3013818

What you say is true for classes, a metaclass is created when the class is defined.  This is all as of 1.8.6, I haven't checked if the specifics of this change in 1.9.

Thanks for reading and your comment.  More importantly, thanks for all of your insanely great &lt;a href="http://www.zenspider.com/ZSS/Products/" rel="nofollow"&gt;tools&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>Hi Ryan,</p>
<p>I&#8217;m afraid your statement, &#8220;EVERY object has a singleton class implicitly, no matter what.&#8221; is not accurate.  Objects have a singleton class created implicitly the first time the singleton class is accessed, but if it is never accessed, there is no singleton class.  Hence the equality issue.  More specifically, the singleton class for an object is created the first time rb_singleton_class (line 854 in class.c) is called.  I used RubyInline to write an example that shows this in action:</p>
<p>require &#8220;inline&#8221;<br />
class Object<br />
  inline do |builder|<br />
    builder.c &#8221;<br />
      VALUE klass(VALUE object) {<br />
        return RBASIC(object)->klass;<br />
      }&#8221;<br />
  end<br />
end</p>
<p>class Point; end</p>
<p>point = Point.new</p>
<p>klass(point).object_id<br />
#=> 3080598<br />
klass(Point.new).object_id<br />
#=> 3080598<br />
def point.spin; end<br />
klass(point).object_id<br />
#=> 3013818</p>
<p>What you say is true for classes, a metaclass is created when the class is defined.  This is all as of 1.8.6, I haven&#8217;t checked if the specifics of this change in 1.9.</p>
<p>Thanks for reading and your comment.  More importantly, thanks for all of your insanely great <a href="http://www.zenspider.com/ZSS/Products/" rel="nofollow">tools</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Berger</title>
		<link>http://www.klankboomklang.com/2007/09/28/real-class/#comment-76</link>
		<dc:creator>Daniel Berger</dc:creator>
		<pubDate>Tue, 02 Oct 2007 21:42:13 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/09/28/real-class/#comment-76</guid>
		<description>Great post.</description>
		<content:encoded><![CDATA[<p>Great post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Davis</title>
		<link>http://www.klankboomklang.com/2007/09/28/real-class/#comment-75</link>
		<dc:creator>Ryan Davis</dc:creator>
		<pubDate>Mon, 01 Oct 2007 04:12:37 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/09/28/real-class/#comment-75</guid>
		<description>Well... I think you're possibly misunderstanding singleton classes. EVERY object has a singleton class implicitly, no matter what. So 'pirate' is still an Object instance (and points would still be Point instances), even if something has been added to its singleton class. Otherwise, you could take this argument to its logical extreme and say that no instances are _ever_ of the same class.

I do agree and would enjoy a ruby with a truley open metaobject protocol.</description>
		<content:encoded><![CDATA[<p>Well&#8230; I think you&#8217;re possibly misunderstanding singleton classes. EVERY object has a singleton class implicitly, no matter what. So &#8216;pirate&#8217; is still an Object instance (and points would still be Point instances), even if something has been added to its singleton class. Otherwise, you could take this argument to its logical extreme and say that no instances are _ever_ of the same class.</p>
<p>I do agree and would enjoy a ruby with a truley open metaobject protocol.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pfarley</title>
		<link>http://www.klankboomklang.com/2007/09/28/real-class/#comment-74</link>
		<dc:creator>pfarley</dc:creator>
		<pubDate>Sun, 30 Sep 2007 01:01:37 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/09/28/real-class/#comment-74</guid>
		<description>Thanks for the endorsement, it's much appreciated.  As long as you're willing to read  'em, I'll keep writing 'em.</description>
		<content:encoded><![CDATA[<p>Thanks for the endorsement, it&#8217;s much appreciated.  As long as you&#8217;re willing to read  &#8216;em, I&#8217;ll keep writing &#8216;em.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: farooq</title>
		<link>http://www.klankboomklang.com/2007/09/28/real-class/#comment-73</link>
		<dc:creator>farooq</dc:creator>
		<pubDate>Sat, 29 Sep 2007 05:58:39 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/09/28/real-class/#comment-73</guid>
		<description>nice post! you do a better at popping the hood than most others, partly because you stick to the point. keep 'em coming!</description>
		<content:encoded><![CDATA[<p>nice post! you do a better at popping the hood than most others, partly because you stick to the point. keep &#8216;em coming!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
