From: Ezra Zygmuntowicz Date: 2006-08-07T03:29:39+09:00 Subject: Re: Singleton methods with method_missing On Aug 6, 2006, at 11:16 AM, Pat Maddox wrote: > I don't have any practical use for this, but I was experimenting a > bit. > I just want to create singleton methods on objects of this class. > There's more to come, but this is the part I'm stuck at :) > > This code doesn't actually work, but I think it's close (I hope?) > > class OneShot > def method_missing(m) def self.method_missing(m) > class << self > define_method(m) { puts m.to_s } > end > send(m) > end > end > > When I do this I get "NameError: undefined local variable or method > `m' > for #>" so I think it means that m just > isn't > in scope for the singleton class. How can I define the singleton > method? Is there any way to use binding here? > > Pat > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > That works unless I misunderstand your question. -Ezra