Class | Haml::Helpers::ErrorReturn
In: | lib/haml/helpers.rb lib/haml/helpers/xss_mods.rb
Parent: | Object

An object that raises an error when \{to_s} is called. It‘s used to raise an error when the return value of a helper is used when it shouldn‘t be.

### Methods

html_safe html_safe! html_safe? inspect new to_s

### Public Class methods

new(method)

@param message [String] The error message to raise when \{to_s} is called

[Source]

        # File lib/haml/helpers.rb, line 12
    12:       def initialize(method)
    13:         @message = "\#{method} outputs directly to the Haml template.\nDisregard its return value and use the - operator,\nor use capture_haml to get the value as a String.\n"
    14:       end

### Public Instance methods

html_safe()

Alias for to_s

html_safe!()

Alias for to_s

html_safe?()

Alias for to_s

inspect()

@return [String] A human-readable string representation

[Source]

        # File lib/haml/helpers.rb, line 44
    44:       def inspect
    45:         "Haml::Helpers::ErrorReturn(#{@message.inspect})"
    46:       end

to_s()

Raises an error.

@raise [Haml::Error] The error

[Source]

        # File lib/haml/helpers.rb, line 24
    24:       def to_s
    25:         raise Haml::Error.new(@message)
    26:       rescue Haml::Error => e
    27:         e.backtrace.shift
    28:
    29:         # If the ErrorReturn is used directly in the template,
    30:         # we don't want Haml's stuff to get into the backtrace,
    31:         # so we get rid of the format_script line.
    32:         #
    33:         # We also have to subtract one from the Haml line number
    34:         # since the value is passed to format_script the line after
    35:         # it's actually used.
    36:         if e.backtrace.first =~ /^\(eval\):\d+:in `format_script/
    37:           e.backtrace.shift
    38:           e.backtrace.first.gsub!(/^\(haml\):(\d+)/) {|s| "(haml):#{$1.to_i - 1}"}
    39:         end
    40:         raise e
    41:       end

[Validate]