Ruby locale yml 中的感叹号是做什么用的?

edokeh · April 19, 2012 · Last by edokeh replied at May 09, 2012 · 5118 hits

https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/zh-CN.yml 比如第 34 行的那个感叹号,但是我翻看 ruby-china 源码的 locale 文件时没看到这种用法 这个感叹号是做什么用的呢? 我猜想是不是为了在 i18n 转换出错时候做静默处理的?

猜测应该是执行代码的功能

#1 楼 @huacnlee 仔细看了下,猜测应该是表示 value 为 string 类型,因为你看别的没有加!的 hash 都没有用单引号 翻看 yml spec 没看到这种用法,有类似的,用!str xxx 表示后面的是字符串 !用来标识 value 的类型,后面接的是类型名称 Explicit typing is denoted with a tag using the exclamation point (“!”) symbol. http://www.yaml.org/spec/1.2/spec.html

You need to Sign in before reply, if you don't have an account, please Sign up first.