模块:RSpec::Matchers::EnglishPhrasing
- 定义于
- lib/rspec/matchers/english_phrasing.rb
概述
便于将 Ruby 对象转换为英文短语。
类方法摘要 折叠
-
.list(obj) ⇒ Object
当给出空列表时。
-
.split_words(sym) ⇒ Object
将符号转换为英文表达式。
类方法详细信息
.list(obj) ⇒Object
注意
返回的字符串包含前导空格,除了
当给出空列表时。
将对象(通常是对象的集合)转换为英文列表。
list(['banana', 'kiwi', 'mango'])
#=> " \"banana\", \"kiwi\", and \"mango\""
给定一个空集合,返回空字符串。
list([]) #=> ""
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rspec/matchers/english_phrasing.rb', line 26 def self.list(obj) return " #{RSpec::Support::ObjectFormatter.format(obj)}" if !obj || Struct === obj || Hash === obj items = Array(obj).map { |w| RSpec::Support::ObjectFormatter.format(w) } case items.length when 0 "" when 1 " #{items[0]}" when 2 " #{items[0]} and #{items[1]}" else " #{items[0...-1].join(', ')}, and #{items[-1]}" end end |
.split_words(sym) ⇒Object
将符号转换为英文表达式。
split_words(:banana_creme_pie) #=> "banana creme pie"
9 10 11 |
# File 'lib/rspec/matchers/english_phrasing.rb', line 9 def self.split_words(sym) sym.to_s.tr('_', ' ') end |