From: Gavin Sinclair Date: 2003-09-09T13:25:58+09:00 Subject: Re: ANN: MetaTags 1.0 > Hi, > > In message "Re: ANN: MetaTags 1.0" > on 03/09/09, Hal Fulton writes: > > |Much easier than I thought. I'll bet there are some gotchas, > |though. > | > |Matz?? > > Yes? It is hard for me to merge this, because > > * it's no better than e.g. "y %{foo: bar}". > * it's against my policy of "syntax should be stable". > > I agree with usefulness of user-defined literals, and this is much > disciplined than generic reader macros, but still we need to discuss > pros and cons. > > matz. A thought occurred to me. If %y{foo: bar} is seen as desirable as a short and simple way of declaring a YAML literal, what about this instead? YAML{foo: bar} Which is implemented as class << YAML def {(str) # whatever ... "YAML.new(str)?? end end Notes: - no syntax clashes as everyone tries to claim %y{...} (I know, this is FUD, but it addresses the known namespace problem) - allowing '{' as a method is a nice general change, maintaining a unified syntax - syntax-wise, Ruby treats YAML{...} as YAML.{%q{...}} - this proposal is, if anything, clearer than %y{foo: bar} without being burdensome - all of the current %_{...} tricks could be implemented in this way (not suggesting they should be, rather, pointing out consistency) e.g. Regexp{...}, Split{...}, Execute{...} I make no attempt at pros and cons here, but it seems like a pretty good idea to me. Gavin