Skip to content

Add support for unary + and - operators#9

Merged
jg-rp merged 4 commits intomainfrom
prefix-operators
May 20, 2025
Merged

Add support for unary + and - operators#9
jg-rp merged 4 commits intomainfrom
prefix-operators

Conversation

@jg-rp
Copy link
Copy Markdown
Owner

@jg-rp jg-rp commented May 19, 2025

Add support for unary + and - operators.

require "liquid2"

env = Liquid2::Environment.new(arithmetic_operators: true)

source = <<~LIQUID.chomp
  {{ -(1+2) }}
  {{ -1+2 }}
  {{ -"42" }}
  {{ +"42" }}
LIQUID

puts env.render(source)
-3
1
-42
42

If the operand can't be coerced to a number following the same semantics as math filters, an instance of Liquid::Undefined is used instead.

@jg-rp jg-rp marked this pull request as ready for review May 20, 2025 06:44
@jg-rp jg-rp merged commit b40cc3b into main May 20, 2025
8 checks passed
@jg-rp jg-rp deleted the prefix-operators branch May 20, 2025 06:46
@jg-rp jg-rp added the feature label Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant