From: sabbyxtabby@... (Sabby and Tabby) Date: 2003-09-29T14:54:14+09:00 Subject: Re: Thoughts on yield nolan_d@bigfoot.com (Nolan J. Darilek) wrote: > I sorta envisioned the language as looking something like: > > clef do > measure("4/4") do > c d e f g a b c > chord do > c e g > end > end > end > > In this example, a-g are methods returning note objects. > > What I'd like is to have that return a list like so: > > ["c", "d", "e", "f", "g", "a", "b", "c", ["c", "e", "g"]] Possible. But not for long. #!/usr/bin/ruby -w def clef yield end def measure(m) @lines = [] yield @lines.inject {|a,b| a.push(*b)} end def chord @lines[-1] = [yield] end ('a'..'g').each {|x| eval <<""} def #{x}(*a) @lines << [] if a.empty? @lines[-1].unshift('#{x}') end notes = clef do measure("4/4") do c d e f g a b c chord do c e g end end end p notes __END__ ../gem:25: warning: parenthesize argument(s) for future version ../gem:25: warning: parenthesize argument(s) for future version ../gem:25: warning: parenthesize argument(s) for future version ../gem:25: warning: parenthesize argument(s) for future version ../gem:25: warning: parenthesize argument(s) for future version ../gem:25: warning: parenthesize argument(s) for future version ../gem:27: warning: parenthesize argument(s) for future version ["c", "d", "e", "f", "g", "a", "b", "c", ["c", "e", "g"]]