Special case Hash#last in variable lookup

Ruby's defines Hash#first via Enumerable but not Hash#last.
This is a confusing behaviour, and it bubbles up to Liquid.

Solution: add a special case for command-lookups of Hash#last to return
hash.values.last.
This commit is contained in:
Sam Doiron
2022-11-01 14:40:36 -03:00
parent 29732f4305
commit cc6cd64065
2 changed files with 9 additions and 1 deletions
+4
View File
@@ -130,4 +130,8 @@ class VariableTest < Minitest::Test
def test_raw_value_variable
assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' })
end
def test_hash_last
assert_template_result('last', '{{ hash.last }}', { 'hash' => { 'first' => 'first', 'last' => 'last' } })
end
end