From 7d7877c166e191f18f0fd65baa1fa4e7065aa03b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Thu, 17 Oct 2024 09:43:02 -0700 Subject: [PATCH] Code style --- lib/sassc/embedded.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/sassc/embedded.rb b/lib/sassc/embedded.rb index 45f1479..50de4d6 100644 --- a/lib/sassc/embedded.rb +++ b/lib/sassc/embedded.rb @@ -139,8 +139,6 @@ class FunctionsHandler remove_method(:setup) if public_method_defined?(:setup, false) def setup(_native_options, functions: Script::Functions) - @callbacks = {} - functions_wrapper = Class.new do attr_accessor :options @@ -148,7 +146,7 @@ def setup(_native_options, functions: Script::Functions) end.new functions_wrapper.options = @options - Script.custom_functions(functions:).each do |custom_function| + Script.custom_functions(functions:).each.with_object({}) do |custom_function, callbacks| callback = lambda do |native_argument_list| function_arguments = arguments_from_native_list(native_argument_list) begin @@ -162,10 +160,8 @@ def setup(_native_options, functions: Script::Functions) raise e end - @callbacks[Script.formatted_function_name(custom_function, functions:)] = callback + callbacks[Script.formatted_function_name(custom_function, functions:)] = callback end - - @callbacks end private @@ -375,8 +371,7 @@ def import_to_native(import, parent_dir, from_import, canonicalize) canonical_url = Uri.path_to_file_url(File.absolute_path(import.path, parent_dir)) @importer_results[canonical_url] = if import.source.is_a?(Hash) { - contents: import.source[:contents], - syntax: import.source[:syntax], + **import.source, source_map_url: canonical_url } else @@ -500,7 +495,7 @@ def self.from_native(value, options) ) when ::Sass::Value::Map ::SassC::Script::Value::Map.new( - value.contents.to_a.to_h { |k, v| [from_native(k, options), from_native(v, options)] } + value.contents.each.with_object({}) { |(k, v), h| h[from_native(k, options)] = from_native(v, options) } ) when ::Sass::Value::Number ::SassC::Script::Value::Number.new( @@ -563,7 +558,7 @@ def self.to_native(value) ) when ::SassC::Script::Value::Map ::Sass::Value::Map.new( - value.value.to_a.to_h { |k, v| [to_native(k), to_native(v)] } + value.value.each.with_object({}) { |(k, v), h| h[to_native(k)] = to_native(v) } ) when ::SassC::Script::Value::Number ::Sass::Value::Number.new( @@ -629,8 +624,8 @@ def parse(...) decode_uri_hash_with_preserve_escaped = if unescaped.nil? || unescaped.empty? decode_uri_hash else - decode_uri_hash.to_h do |key, value| - [key, unescaped.include?(value) ? key : value] + decode_uri_hash.each.with_object({}) do |(key, value), hash| + hash[key] = unescaped.include?(value) ? key : value end.freeze end