Now that is a super cool ruby hack. Thank you.

I was able to mold it to the way I wanted it. Now it can temporarily define
a method, call the method with arguments and then undefine the temporary
method. I'm guessing this comes with a cost? slowness?

class Foo
  def red(&p)
    @z = p
  end

  def blue(y)
    Foo.send(:define_method, :blue_temp, @z)
    blue_temp(y)
    Foo.send(:undef_method, :blue_temp)
  end

  def green
    puts "Yeah!"
  end
end

x = Foo.new

x.red do |y|
 green
 puts y
end

x.blue 5














"Sean O'Halpin" <sean.ohalpin / gmail.com> wrote in message
news:3736dd30510111609t1b096d20rda04361197abc6b8 / mail.gmail.com...
This isn't quite what you asked for but it achieves the same effect:

class Foo
 def red(&p)
   self.class.send(:define_method, :z, &p)
 end

 def blue(y)
  puts y
  z(y)
 end

 def green
   puts "Yeah!"
 end
end

x = Foo.new

x.red do |y|
 green
 puts y
end

x.blue 5
__END__
5
Yeah!
5

Regards,

Sean