Class Haml::Helpers::ErrorReturn
In: lib/haml/helpers.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

inspect   new   to_s  

Public Class methods

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

[Source]

    # File lib/haml/helpers.rb, line 17
17:       def initialize(method)
18:         @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"
19:       end

Public Instance methods

@return [String] A human-readable string representation

[Source]

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

Raises an error.

@raise [Haml::Error] The error

[Source]

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

[Validate]