class Wordlist::Modifiers::Tr
Lazily calls ‘String#tr` on every word in the wordlist.
@since 1.0.0
Attributes
chars[R]
The characters or character range to translate.
@return [String]
replace[R]
The characters or character range to translate to.
@return [String]
Public Class Methods
new(wordlist,chars,replace)
click to toggle source
Initializes the ‘String#tr` modifier.
@param [String] chars
The characters or character range to replace.
@param [String] replace
The characters or character range to use as the replacement.
Calls superclass method
Wordlist::Modifiers::Modifier::new
# File lib/wordlist/modifiers/tr.rb, line 32 def initialize(wordlist,chars,replace) super(wordlist) @chars = chars @replace = replace end
Public Instance Methods
each() { |tr| ... }
click to toggle source
Enumerates over every ‘tr`ed word in the wordlist.
@yield [word]
The given block will be passed each `tr`ed word.
@yieldparam [String] word
A `tr`ed word.
@return [Enumerator]
If no block is given, an Enumerator object will be returned.
@example
wordlist = Wordlist::Words["foo", "bar", "baz"] wordlist.tr("oa", "0@").each do |word| puts word end # f00 # b@r # b@z
@api public
# File lib/wordlist/modifiers/tr.rb, line 62 def each return enum_for(__method__) unless block_given? @wordlist.each do |word| yield word.tr(@chars,@replace) end end