<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'define_method in instance_eval' | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/77/topics/561</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>define_method in instance_eval posted by James Whiteman @ Thu, 19 Jun 2008 16:09:13 -0000</title>
      <description>&lt;p&gt;Thanks, Dave&amp;#8212;fantastic series by the way.&lt;/p&gt;</description>
      <pubDate>Thu, 19 Jun 2008 16:09:13 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:77:561:3248</guid>
      <author>James Whiteman</author>
      <link>http://forums.pragprog.com/forums/77/topics/561</link>
    </item>
    <item>
      <title>define_method in instance_eval posted by Dave Thomas @ Thu, 19 Jun 2008 12:53:19 -0000</title>
      <description>&lt;p&gt;define_method always creates an instance method&amp;#8212;now idea why, but it&amp;#8217;s a deliberate decision of the implementers.&lt;/p&gt;


	&lt;p&gt;Dave&lt;/p&gt;</description>
      <pubDate>Thu, 19 Jun 2008 12:53:19 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:77:561:3242</guid>
      <author>Dave Thomas</author>
      <link>http://forums.pragprog.com/forums/77/topics/561</link>
    </item>
    <item>
      <title>define_method in instance_eval posted by James Whiteman @ Wed, 18 Jun 2008 23:17:40 -0000</title>
      <description>&lt;p&gt;Hello, all.&lt;/p&gt;


	&lt;p&gt;Does anyone have a good explanation for this?&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
class Foo
end

Foo.instance_eval do
  def jump
    "jumping..." 
  end

  define_method(:shout) do
    "shouting..." 
  end
end

Foo.respond_to? :jump
  =&amp;gt; true
Foo.respond_to? :shout
  =&amp;gt; false
Foo.new.respond_to? :shout
  =&amp;gt; true
&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;

	&lt;p&gt;It seems that define_method is pushing the method &amp;#8216;shout&amp;#8217; into Foo&amp;#8217;s own m_tbl instead of in the metaclass.&lt;br /&gt;This was a little unexpected to me.&lt;/p&gt;</description>
      <pubDate>Wed, 18 Jun 2008 23:17:40 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:77:561:3232</guid>
      <author>James Whiteman</author>
      <link>http://forums.pragprog.com/forums/77/topics/561</link>
    </item>
  </channel>
</rss>
