From: Benny Date: 2004-04-19T22:54:07+09:00 Subject: Re: YAML question: calling a method Joel VanderWerf wrote: > Benny wrote: >> hi, >> >> from what I've learned from the yaml.rb docs I can initialize an object >> in YAML with >> >> !ruby/object:Classname >> para1: val1 >> para2: val2 >> >> now how can I call a specific method of this object (in YAML as well)? > > Not sure what you mean by calling a method in YAML, but you can do this: > I would like to do something like this ## YAML-File - !ruby/variable:x = !ruby/object:Some_Cool_Class para1: val1 para2: val2 - !ruby/variable:y = !ruby/method:x.get_somethings_for_me - new data for us stuff: !ruby/hash-value: y['some_key'] other stuff: !ruby/hash-value: y['some__other_key'] ## parsing Ruby-file require 'yaml' class Some_Cool_Class def initialize p1, p2 @para1 = p1 @para2 = p2 end def get_somethings_for_me puts "making something really complicated" return { 'some_key' => 'some value', 'some__other_key' => 'some other value' } end end result = YAML.load(str) benny