Class: Haml::Helpers::ErrorReturn

### Home Classes Methods

### In Files

- lib/haml/helpers.rb
- lib/haml/helpers/xss_mods.rb

### Parent

Object

### Methods

- ::new
- #html_safe
- #html_safe!
- #html_safe?
- #inspect
- #to_s

### Class/Module Index

Quicksearch

- Haml
- Haml::Buffer
- Haml::Compiler
- Haml::Engine
- Haml::Error
- Haml::ErubisTemplateHandler
- Haml::Exec
- Haml::Exec::Generic
- Haml::Exec::Haml
- Haml::Filters
- Haml::Filters::Base
- Haml::Filters::Cdata
- Haml::Filters::Css
- Haml::Filters::Erb
- Haml::Filters::Escaped
- Haml::Filters::Javascript
- Haml::Filters::Plain
- Haml::Filters::PrecompiledTiltFilter
- Haml::Filters::Preserve
- Haml::Filters::Ruby
- Haml::Filters::SassRailsTemplate
- Haml::Filters::ScssRailsTemplate
- Haml::Filters::TiltFilter
- Haml::Helpers
- Haml::Helpers::ActionViewExtensions
- Haml::Helpers::ErrorReturn
- Haml::Helpers::XssMods
- Haml::Options
- Haml::Parser
- Haml::Parser::Line
- Haml::Parser::ParseNode
- Haml::Plugin
- Haml::Railtie
- Haml::SafeErubisTemplate
- Haml::SyntaxError
- Haml::Template
- Haml::Util
- Haml::Util::StaticConditionalContext
- ActionView
- ActionView::Base
- ActionView::Helpers
- ActionView::Helpers::CaptureHelper
- ActionView::Helpers::FormHelper
- ActionView::Helpers::FormTagHelper
- ActionView::Helpers::HamlSupport
- ActionView::Helpers::InstanceTag
- ActionView::Helpers::TagHelper
- ActionView::Helpers::Tags
- ActionView::Helpers::Tags::TextArea
- ActionView::Helpers::TextHelper
- Object

No matching classes.

# Haml::Helpers::ErrorReturn

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.

### Public Class Methods

new(method) click to toggle source

    # File lib/haml/helpers.rb, line 11
    def initialize(method)
      @message = #{method} outputs directly to the Haml template.Disregard its return value and use the - operator,or use capture_haml to get the value as a String.
    end

### Public Instance Methods

html_safe() click to toggle source

Any attempt to treat ErrorReturn as a string should cause it to blow up.

Alias for: to_s
html_safe!() click to toggle source
Alias for: to_s
html_safe?() click to toggle source
Alias for: to_s
inspect() click to toggle source

@return [String] A human-readable string representation

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

to_s() click to toggle source

Raises an error.

@raise [Haml::Error] The error

    # File lib/haml/helpers.rb, line 22
    def to_s
      raise Haml::Error.new(@message)
    rescue Haml::Error => e
      e.backtrace.shift

      # If the ErrorReturn is used directly in the template,
      # we don't want Haml's stuff to get into the backtrace,
      # so we get rid of the format_script line.
      #
      # We also have to subtract one from the Haml line number
      # since the value is passed to format_script the line after
      # it's actually used.
      if e.backtrace.first =~ /^\(eval\):\d+:in `format_script/
        e.backtrace.shift
        e.backtrace.first.gsub!(/^\(haml\):(\d+)/) {|s| "(haml):#{$1.to_i - 1}"}
      end
      raise e
    end

Also aliased as: html_safe, html_safe?, html_safe!

[Validate]

Generated with the Darkfish Rdoc Generator 2.