Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/core_extensions/string.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#to_view_code ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/core_extensions/string.rb', line 17 def to_view_code class << self def inspect super.gsub(/^"(.*)"$/,'\1') end end return self end |