On Aug 23, 2007, at 2:10 PM, Zeekar wrote:

> In case the goal isn't clear, I want instance (not singleton/class)
> methods of a given class to have access to what are essentially helper
> functions/subroutines (not other instance methods of the same class)
> which are not generally accessible outside of that class.

easy:

cfp:~ > cat a.rb
class C
   singleton_class =
     class << self
       self
     end

   helper = Object.new.instance_eval do
     def foo() 42 end
     self
   end

   [self, singleton_class].each do |c|
     c.module_eval{
       define_method(:helper){ helper }
       private :helper
     }
   end

   def initialize
     @foo = helper.foo
   end
end

p C.new
C.helper


cfp:~ > ruby a.rb
#<C:0x24b94 @foo=42>
a.rb:25: private method `helper' called for C:Class (NoMethodError)


but in the presence of both instance_eval, eval, and send - why bother?

a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama