I rewrote it without all the crazy Module.new and Class.new stuff<br>and it still doesnt make any sense<br><br><a href="http://gist.github.com/218649">http://gist.github.com/218649</a><br><br><div class="gmail_quote">2009/10/26 Anthony Green <span dir="ltr"><<a href="mailto:Anthony.Green@bbc.co.uk">Anthony.Green@bbc.co.uk</a>></span><br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
I hope James won't mind me posting this Gist he tweeted at the weekend. But<br>
it exemplifies the kind of gaps I have in my Ruby knowledge.<br>
Whilst I understand what individual segments of code are doing I don't<br>
understand what the code as a whole is attempting to do.<br>
<br>
Anyone willing to shed some light ?<br>
<br>
<a href="http://gist.github.com/217001" target="_blank">http://gist.github.com/217001</a><br>
<br>
<br>
# I'm creating some classes and modules on the fly, but things aren't<br>
hooking up quite the way I'd hoped.<br>
# Can anyone explain why when an instance of Mod::Sibling tries to call<br>
<br>
Child.cry, that it<br>
<br>
# doesn't call Mod::Child.cry, but instead looks for Behaviour::Child?<br>
 <br>
class Base<br>
  def self.cry<br>
    "#{<a href="http://self.name" target="_blank">self.name</a>}.cry called!"<br>
  end<br>
end<br>
 <br>
module Behaviour<br>
  def blame<br>
    puts "I am #{self}, a #{<a href="http://self.class.name" target="_blank">self.class.name</a>}, trying to call Child.cry"<br>
    Child.cry<br>
  end<br>
end<br>
 <br>
child = Class.new(Base)<br>
 <br>
Mod = Module.new<br>
Mod.const_set(:Child, child)<br>
 <br>
child.cry # => "Mod::Child.cry called!"<br>
Mod::Child.cry # => "Mod::Child.cry called!"<br>
<a href="http://child.name" target="_blank">child.name</a> # => "Mod::Child"<br>
 <br>
sibling = Class.new(Base)<br>
sibling.class_eval do<br>
  include Behaviour<br>
end<br>
Mod.const_set(:Sibling, sibling)<br>
<a href="http://sibling.name" target="_blank">sibling.name</a> # => "Mod::Sibling"<br>
 <br>
Mod.constants # => ["Child", "Sibling"]<br>
 <br>
sibling = Mod::Sibling.new<br>
sibling.blame # =><br>
# ~> -:10:in `blame': uninitialized constant Behaviour::Child (NameError)<br>
# ~>  from -:32<br>
# >> I am #<Mod::Sibling:0x1973078>, a Mod::Sibling, trying to call<br>
Child.cry<br>
<br>
<br>
<br>
<br>
<br>
--<br>
Anthony Green<br>
Client Side Developer<br>
Future Media & Technology for BBC Audio & Music Interactive<br>
<br>
<br>
<a href="http://www.bbc.co.uk/" target="_blank">http://www.bbc.co.uk/</a><br>
This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.<br>
If you have received it in error, please delete it from your system.<br>
Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.<br>
Please note that the BBC monitors e-mails sent or received.<br>
Further communication will signify your consent to this.<br>
<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div><br>