On Sep 19, 5:38 ¨Âí¬ ÂòéáÃáîäìå¼â®ãáîä®®®Àðïâïø®ãïí÷òïôåº > Thomas Sawyer wrote: > > Has anyone ever endeavored to create a data/configuration file format > > based on Ruby's syntax? In other words, a format like YAML but with a > > Ruby-based syntax. > > Which bit of Ruby syntax are you thinking of? > > If you wanted key/value pairs in a Hash, then you might as well use > JSON. It's not pretty for config files, but it's OK. > > If you wanted > > foo = 123 > > then that's hard to make work, although maybe you could frig it with > binding and local_variables. You could instead use the Rails way: > > config.foo = 123 > > or use constants: > > module Config > Foo = 123 > end > > or globals: > > $foo = 123 > > The Sinatra way would be: > > set :foo, 123 > set(:bar) { delayed_expr } > > Maybe what you're trying to do is > > foo 123 Yes, I should have been more specific. This is what I mean. A longer example: name "Joe Foo" age 33 contact do email "joe / joefoo.com" phione "555-555-1234" end > I don't see a particular problem with that, even with $SAFE=4 and > method_missing: > > >> $h = {} > => {} > >> def method_missing(k,v); $h[k] = v; end > => nil > >> t = Thread.new { $SAFE=4; eval "foo 123" } > > => #<Thread:0x7f4eb7749a48 dead>>> t.join > > SecurityError: (irb):2:in `[]=': Insecure: can't modify hash > from (irb):3 > from (irb):4:in `join' > from (irb):4 > from :0>> $h.taint > => {} > >> t = Thread.new { $SAFE=4; eval "foo 123" } > > => #<Thread:0x7f4eb7726930 dead>>> t.join > > => #<Thread:0x7f4eb7726930 dead>>> $h > > => {:foo=>123} > > This is using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] Ah. You are right. I made a mistake in my experiments. And thank you for this example, #taint made all the difference. So now the question: is $SAFE=4 safe enough? My gut says no. Even though the above works, I think ultimately a true data format is desirable for most needs, such as configuration files. I think Ruby has a very nice syntax for it. Such a format would be to Ruby as JSON is to Javascript. And Ruby has a nice advantage with blocks.