Module: Tk::CoreExtensions::Regexp

Defined in:
lib/ffi-tk/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#to_tclObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ffi-tk/core_extensions.rb', line 84

def to_tcl
  embed = []
  embed << 'i' if options & ::Regexp::IGNORECASE != 0
  embed << 'x' if options & ::Regexp::EXTENDED != 0
  embed << 'n' if options & ::Regexp::MULTILINE != 0

  if embed.empty?
    pattern = source
  else
    pattern = "(?#{embed.join})#{source}"
  end

  TclString.new(%({#{pattern.gsub(/([^\\])(?=[{}])/, '\1\\\\\2')}}))
end