Methods

Class Index

Quicksearch

Arrow::StringExtensions

Add some stuff to the String class to allow easy transformation to Regexp and in-place interpolation.

Public Instance Methods

interpolate( scope ) click to toggle source

Interpolate any ’#{…}’ placeholders in the string within the given scope (a Binding object).

    # File /Users/ged/source/ruby/Arrow/lib/arrow/monkeypatches.rb, line 61
61:     def interpolate( scope )
62:         unless scope.is_a?( Binding )
63:             raise TypeError, "Argument to interpolate must be a Binding, not "\
64:                 "a #{scope.class.name}"
65:         end
66: 
67:         # $stderr.puts ">>> Interpolating '#{self}'..."
68: 
69:         copy = self.gsub( /"/, %q:\": )
70:         eval( '"' + copy + '"', scope )
71:     rescue Exception => err
72:         nicetrace = err.backtrace.find_all {|frame|
73:             /in `(interpolate|eval)'/i !~ frame
74:         }
75:         Kernel.raise( err, err.message, nicetrace )
76:     end
to_re( casefold=false, extended=false ) click to toggle source

Return the receiving String as a Regexp.

    # File /Users/ged/source/ruby/Arrow/lib/arrow/monkeypatches.rb, line 51
51:     def to_re( casefold=false, extended=false )
52:         return Regexp.new( self.dup )
53:     end

secsequence

--- SEC00088

seccomment

--- ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000184
    name: interpolate
    sourcecode: "    <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/monkeypatches.rb, line 61</span>\n\
      61:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">interpolate</span>( <span class=\"ruby-identifier\">scope</span> )\n\
      62:         <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">scope</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">Binding</span> )\n\
      63:             <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">TypeError</span>, <span class=\"ruby-value str\">&quot;Argument to interpolate must be a Binding, not &quot;</span>\\\n\
      64:                 <span class=\"ruby-node\">&quot;a #{scope.class.name}&quot;</span>\n\
      65:         <span class=\"ruby-keyword kw\">end</span>\n\
      66: \n\
      67:         <span class=\"ruby-comment cmt\"># $stderr.puts &quot;&gt;&gt;&gt; Interpolating '#{self}'...&quot;</span>\n\
      68: \n\
      69:         <span class=\"ruby-identifier\">copy</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">gsub</span>( <span class=\"ruby-regexp re\">/&quot;/</span>, <span class=\"ruby-value str\">%q:\\&quot;:</span> )\n\
      70:         <span class=\"ruby-identifier\">eval</span>( <span class=\"ruby-value str\">'&quot;'</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">copy</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">'&quot;'</span>, <span class=\"ruby-identifier\">scope</span> )\n\
      71:     <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Exception</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">err</span>\n\
      72:         <span class=\"ruby-identifier\">nicetrace</span> = <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">find_all</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">frame</span><span class=\"ruby-operator\">|</span>\n\
      73:             <span class=\"ruby-regexp re\">/in `(interpolate|eval)'/i</span> <span class=\"ruby-operator\">!~</span> <span class=\"ruby-identifier\">frame</span>\n\
      74:         }\n\
      75:         <span class=\"ruby-constant\">Kernel</span>.<span class=\"ruby-identifier\">raise</span>( <span class=\"ruby-identifier\">err</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">message</span>, <span class=\"ruby-identifier\">nicetrace</span> )\n\
      76:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Interpolate any &#8217;#{&#8230;}&#8217; placeholders in the string within
      the given <tt>scope</tt> (a Binding object).
      </p>
    params: ( scope )
  - visibility: public
    aref: M000183
    name: to_re
    sourcecode: "    <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/monkeypatches.rb, line 51</span>\n\
      51:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">to_re</span>( <span class=\"ruby-identifier\">casefold</span>=<span class=\"ruby-keyword kw\">false</span>, <span class=\"ruby-identifier\">extended</span>=<span class=\"ruby-keyword kw\">false</span> )\n\
      52:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">Regexp</span>.<span class=\"ruby-identifier\">new</span>( <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">dup</span> )\n\
      53:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Return the receiving String as a Regexp.
      </p>
    params: ( casefold=false, extended=false )
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.