Class: Haml::RubyExpression

Inherits:
Ripper
  • Object
show all
Defined in:
lib/haml/ruby_expression.rb

Defined Under Namespace

Classes: ParseError

Class Method Summary collapse

Class Method Details

.string_literal?(code) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
# File 'lib/haml/ruby_expression.rb', line 15

def self.string_literal?(code)
  return false if syntax_error?(code)

  type, instructions = Ripper.sexp(code)
  return false if type != :program
  return false if instructions.size > 1

  type, _ = instructions.first
  type == :string_literal
end

.syntax_error?(code) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
# File 'lib/haml/ruby_expression.rb', line 8

def self.syntax_error?(code)
  self.new(code).parse
  false
rescue ParseError
  true
end