Skip to content

Commit

Permalink
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/compiler/crystal/macros.cr
Original file line number Diff line number Diff line change
@@ -542,6 +542,10 @@ module Crystal::Macros
def splat(trailing_string : StringLiteral = nil) : MacroId
end

# Similar to `Array#clear`
def clear : ArrayLiteral
end

# Similar to `Array#empty?`
def empty? : BoolLiteral
end
@@ -625,6 +629,10 @@ module Crystal::Macros

# A hash literal.
class HashLiteral < ASTNode
# Similar to `Hash#clear`
def clear : HashLiteral
end

# Similar to `Hash#empty?`
def empty? : BoolLiteral
end
10 changes: 10 additions & 0 deletions src/compiler/crystal/macros/methods.cr
Original file line number Diff line number Diff line change
@@ -753,6 +753,11 @@ module Crystal
interpret_argless_method(method, args) { @of || Nop.new }
when "type"
interpret_argless_method(method, args) { @name || Nop.new }
when "clear"
interpret_argless_method(method, args) do
elements.clear
self
end
else
value = intepret_array_or_tuple_method(self, ArrayLiteral, method, args, block, interpreter)
value || super
@@ -837,6 +842,11 @@ module Crystal
interpret_argless_method(method, args) { @of.try(&.value) || Nop.new }
when "type"
interpret_argless_method(method, args) { @name || Nop.new }
when "clear"
interpret_argless_method(method, args) do
entries.clear
self
end
else
super
end

0 comments on commit 8bc3cee

Please sign in to comment.