class String

We use Hash#inspect in ExpressTemplates::Markup::Wrapper to reproduce arguments to helpers in the Rails view.

Hash#inspect calls inspect on values and keys. This allows us to place the resulting string into the view code with a simple substitution or concatenation.

In special cases, however, we might want the argument or one of its keys or values to be the result of evaluating of a ruby expression in the view that does not itself return a String. The result of inspect is normally a quoted and escaped string which would evaluate to a string in the view. What we want is a simple string of code. Here we provide a method that overrides inspect in the strings eigenclass to strip off enclosing quotes or unwanted escapes. It shouldn't bother anybody and it keeps us from doing messy things elsewhere for now.

Public Class Methods

inspect() click to toggle source
Calls superclass method
# File lib/core_extensions/string.rb, line 19
def inspect
  super.gsub(/^"(.*)"$/,'\1')
end

Public Instance Methods

to_view_code() click to toggle source
# File lib/core_extensions/string.rb, line 17
def to_view_code
  class << self
    def inspect
      super.gsub(/^"(.*)"$/,'\1')
    end
  end
  return self
end