>Basically I'd like to do something like this: > >Say MyClass.initialize is something like this: > >def MyClass > def initialize ( a, b, &c ) > @a, @b, @c = a, b, c > end >end >functions = # ... an array of 'things' >m = MyClass.new( someParameter, someOther ) >functions.each { | funct | > m = MyClass.setFunction funct > # invoce some methods of m (that use funct via the member @c) >} > >Is there a way to do this? > Seems to me you need a way to create blocks of code as objects. If so Proc is your class and proc is your shortcut. Try: class MyClass def initialize(a, b, &c) @a, @b, @c = a, b, c end def set_function(c) @c = c end def apply return @c.call(@a), @c.call(@b) end end functions = [proc{|x| x+1}, proc{|x| x*x}] m = MyClass.new(1, 2) functions.each do |f| m.set_function(f) puts m.apply.inspect end puts functions[0].type which prints $ ruby functor_question_ruby_talk_22402.rb [2, 3] [1, 4] Proc Regards, Robert