From: ptkwt@... (Phil Tomson) Date: 2003-09-28T15:11:03+09:00 Subject: Re: Thoughts on yield Here's take 3. This one seems to work: module Music def initialize @notes = [] @chord_notes=[] @tmp_notes = [] end def a(list=@tmp_notes) list << "a" end def b(list=@tmp_notes) list << "b" end def c(list=@tmp_notes) list << "c" end def d(list=@tmp_notes) list << "d" end def e(list=@tmp_notes) list << "e" end def f(list=@tmp_notes) list << "f" end def g(list=@tmp_notes) list << "g" end def clef puts "...In Clef..." yield @notes = @tmp_notes @notes << @chord_notes unless @chord_notes.empty? return @notes end def measure(time) puts "...In Measure..." yield end def chord tmpnotes = @tmp_notes.dup @tmp_notes.clear puts "...In Chord..." yield @chord_notes @chord_notes = @tmp_notes @tmp_notes = tmpnotes end def notes @notes end end class Song include Music def define_song(&b) instance_eval &b end end mysong= Song.new mysong.define_song { clef do measure("4/4") do c; d; e; f; g; a; b; c; chord do c; d; g; end end end } p mysong.notes This way the user doesn't even have to define a class, call super and all those Ruby details. Thanks to Joel for the instance_eval suggestion. Phil