From: Onur Gungor Date: 2008-06-05T18:40:25+09:00 Subject: Re: variable in lambda salamond wrote: > Hi, all. > > I came across the following problem. > I need to generate a couple of methods, > by now, I'm using > acode = lambda { > puts "i am a student in class " + c > } acode = lambda { |c| lambda { puts "i am a student in class " + c } > > bcode = lambda { > puts "class "+c+ "is a great class" > } bcode = lambda { |c| lambda { puts "class "+c+ "is a great class" } } > > ["a", "b", "c"].each do |c| > define_method("student_in_class"+c, acode) > define_method("greate_class"+c, bcode) > end ["a", "b", "c"].each do |c| define_method("student_in_class"+c, acode.call(c)) define_method("greate_class"+c, bcode.call(c)) end > > now ruby doesn't seem to recognize c in acode and bcode. > is there any alternatives? > > thx > JarodZZ I think this will do the trick. onur -- Posted via http://www.ruby-forum.com/.