Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/re_expand.rb

Instance Method Summary collapse

Instance Method Details

#expand(filterpat = ' ', ambig = 0, &block) ⇒ Object

restr.expand { |a| … } restr.expand(‘ abc ’){ |a| … } パタンを指定 restr.expand(‘ abc ’,1){ |a| … } 許容曖昧度を指定



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/re_expand.rb', line 18

def expand(filterpat=' ',ambig=0,&block)
  g = ExpandRuby::Generator.new
  g.add(self,'')
  strings = []

  if block_given? then
    g.generate(filterpat,ambig,&block)
  else
    m = g.generate(filterpat)
    matched = m[0].length > 0 ? m[0] : m[1].length > 0 ? m[1] : m[2]
    strings = matched.collect { |r|
      r[0]
    }
  end
end