From: Ross Bamford Date: 2006-05-14T16:36:57+09:00 Subject: Re: "Seeing Metaclasses Clearly" On Sun, 2006-05-14 at 15:28 +0900, Pat Maddox wrote: > I saw a link for why's article "Seeing Metaclasses Clearly" [1] > earlier this week. Been looking at it, and honestly I can't say it's > making things more clear for me. The final example is: > > class MailTruck > def self.company( name ) > meta_def :company do; name; end > end > end > > class HappyTruck < MailTruck > company "Happy's -- We Bring the Mail, and That's It!" > end > > I simply don't see how that's different from > > class MailTruck > def self.company(name) > instance_eval do > define_method(name) { name } > end > end > end > I'm sure this is probably a typo, but the above code isn't doing exactly what it's supposed to: class HappyTruck < MailTruck company "Happy's -- We Bring the Mail, and That's It!" end puts HappyTruck.instance_methods # dup # hash # private_methods # [...] # Happy's -- We Bring the Mail, and That's It! # [...] puts HappyTruck.new.send("Happy's -- We Bring the Mail, and That's It!") # Happy's -- We Bring the Mail, and That's It! I.e. you're making an instance method named for the argument passed into the class-level 'company'. ruby is pretty relaxed about that, but obviously it can't be called without using send. Switching to 'define_method(:company) { name }' made it work as (I think) _why intended. -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk