Hi,

This is better - it defines the z method on the singleton class of the
instance object.

--- CODE ---
class Foo
  def singleton
    class<<self; self; end
  end

  def red(&block)
    singleton.send(:define_method, :z, &block)
  end

  def blue(y)
    z(y)
  end

  def green
    puts "Yeah!"
  end

end

x = Foo.new

x.red do |y|
 green
 puts y
end

x.blue 5

a = Foo.new
a.blue 42
# we want this to cause the exception below (because no red block defined)

__END__

Yeah!
5
undefined method `z' for #<Foo:0x2870b38> (NoMethodError)

--- END OF CODE ---

Regards,

Sean