mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
26 lines
583 B
Ruby
26 lines
583 B
Ruby
|
module Sass::Constant
|
||
|
class UnaryOperation # :nodoc:
|
||
|
def initialize(operand, operator)
|
||
|
@operand = operand
|
||
|
@operator = operator
|
||
|
end
|
||
|
|
||
|
def to_s
|
||
|
self.perform.to_s
|
||
|
end
|
||
|
|
||
|
def inspect
|
||
|
"(#{@operator.inspect} #{@operand.inspect})"
|
||
|
end
|
||
|
|
||
|
def perform
|
||
|
operator = "unary_#{@operator}"
|
||
|
literal = @operand.perform
|
||
|
literal.send(operator)
|
||
|
rescue NoMethodError => e
|
||
|
raise e unless e.name.to_s == operator.to_s
|
||
|
raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{literal}\".")
|
||
|
end
|
||
|
end
|
||
|
end
|