lib/code/object/string.rb in code-ruby-0.4.0 vs lib/code/object/string.rb in code-ruby-0.5.0

- old
+ new

@@ -8,21 +8,22 @@ end def call(**args) operator = args.fetch(:operator, nil) arguments = args.fetch(:arguments, []) - globals = args.multi_fetch(*::Code::GLOBALS) + globals = multi_fetch(args, *::Code::GLOBALS) + value = arguments.first&.value - if operator == "to_function" + if operator == "&" || operator == "to_function" sig(arguments) to_function(**globals) elsif operator == "+" - sig(arguments, ::Code::Object) - plus(arguments.first.value) + sig(arguments) { ::Code::Object } + plus(value) elsif operator == "*" - sig(arguments, ::Code::Object::Number) - multiplication(arguments.first.value) + sig(arguments) { ::Code::Object::Number } + multiplication(value) elsif operator == "reverse" sig(arguments) reverse else super @@ -50,16 +51,25 @@ def to_function(**globals) ::Code::Node::Code.new( [ { function: { - arguments: [{ regular: { name: "_" } }], + parameters: [{ name: "_" }], body: [ - { call: { left: { name: "_" }, right: [{ name: raw }] } }, - ], - }, - }, - ], + { + chained_call: { + first: { + call: { + name: "_" + } + }, + others: [{ call: { name: raw } }] + } + } + ] + } + } + ] ).evaluate(**globals) end def plus(other) ::Code::Object::String.new(raw + other.to_s)