lib/code/object/dictionnary.rb in code-ruby-0.3.1 vs lib/code/object/dictionnary.rb in code-ruby-0.4.0
- old
+ new
@@ -8,24 +8,39 @@
end
def call(**args)
operator = args.fetch(:operator, nil)
arguments = args.fetch(:arguments, [])
- context = args.fetch(:context)
- io = args.fetch(:io)
+ globals = args.multi_fetch(*::Code::GLOBALS)
if operator == "values"
- values(arguments)
+ sig(arguments)
+ values
+ elsif operator == "keys"
+ sig(arguments)
+ keys
elsif operator == "each"
- each(arguments, context: context, io: io)
+ sig(arguments, ::Code::Object::Function)
+ each(arguments.first.value, **globals)
elsif key?(operator)
- fetch(operator)
+ result = fetch(operator)
+
+ if result.is_a?(::Code::Object::Function)
+ result.call(**args.merge(operator: nil))
+ else
+ sig(arguments)
+ result
+ end
else
super
end
end
+ def merge(other)
+ ::Code::Object::Dictionnary.new(raw.merge(other.raw))
+ end
+
def fetch(key)
raw.fetch(key)
end
def [](key)
@@ -52,27 +67,28 @@
to_s
end
private
- def values(arguments)
- sig(arguments)
+ def keys
+ ::Code::Object::List.new(raw.keys)
+ end
+
+ def values
::Code::Object::List.new(raw.values)
end
- def each(arguments, context:, io:)
- sig(arguments, ::Code::Object::Function)
- argument = arguments.first.value
+ def each(argument, **globals)
raw.each do |key, value|
argument.call(
arguments: [
::Code::Object::Argument.new(key),
- ::Code::Object::Argument.new(value)
+ ::Code::Object::Argument.new(value),
],
- context: context,
- io: io,
+ **globals,
)
end
+
self
end
end
end
end