From: Joel VanderWerf Date: 2009-06-05T04:56:19+09:00 Subject: Re: Use methods from a library in my own class Jason Lillywhite wrote: > 2. How do I apply your idea to methods within an embedded array block > such as "plot.data" from my code: > > plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| > ds.with = "lines" > end > > which has methods such as ds.linewidth, ds.title, etc? I tried multiple > things like creating 2 hashes but can't get my hash values to pass into > the embedded array. Thank you! Something like this? require 'gnuplot' class Data2d def self.plot(x, y, options={}) Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| options.each {|opt,val| plot.send opt, val} ds_options = options[:ds] plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| ds_options.each {|opt,val| ds.send opt, val} end end end end end Data2d.plot(x,y,:x_label=>"Time",:y_label=>"Values", :title=>"My First Plot", :ds => {:with => "lines"}) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407