Skip to content

Commit 2bbab0b

Browse files
committed
Replace .to_h { block } with .each.with_object({}) { block }
1 parent 1585726 commit 2bbab0b

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

lib/sass/compiler/host/protofier.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def to_proto(obj)
3939
argument_list: EmbeddedProtocol::Value::ArgumentList.new(
4040
id: obj.instance_eval { @id },
4141
contents: obj.to_a.map { |element| to_proto(element) },
42-
keywords: obj.keywords.to_h { |key, value| [key.to_s, to_proto(value)] },
42+
keywords: obj.keywords.each.with_object({}) { |(key, value), hash| hash[key.to_s] = to_proto(value) },
4343
separator: ListSeparator.to_proto(obj.separator)
4444
)
4545
)
@@ -126,8 +126,8 @@ def from_proto(proto)
126126
obj.contents.map do |element|
127127
from_proto(element)
128128
end,
129-
obj.keywords.entries.to_h do |key, value|
130-
[key.to_sym, from_proto(value)]
129+
obj.keywords.to_enum.with_object({}) do |(key, value), hash|
130+
hash[key.to_sym] = from_proto(value)
131131
end,
132132
ListSeparator.from_proto(obj.separator)
133133
).instance_eval do
@@ -144,8 +144,8 @@ def from_proto(proto)
144144
)
145145
when :map
146146
Sass::Value::Map.new(
147-
obj.entries.to_h do |entry|
148-
[from_proto(entry.key), from_proto(entry.value)]
147+
obj.entries.to_enum.with_object({}) do |entry, hash|
148+
hash[from_proto(entry.key)] = from_proto(entry.value)
149149
end
150150
)
151151
when :compiler_function

lib/sass/serializer.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@ module Sass
55
module Serializer
66
module_function
77

8-
CSS_ESCAPE = {
9-
"\0" => "\uFFFD",
10-
'\\' => '\\\\',
11-
'"' => '\\"',
12-
"'" => "\\'",
13-
**[*"\x01".."\x08", *"\x0A".."\x1F", "\x7F"].product(
14-
[*'0'..'9', *'a'..'f', *'A'..'F', "\t", ' ', nil]
15-
).to_h do |c, x|
16-
["#{c}#{x}".freeze, "\\#{c.ord.to_s(16)}#{" #{x}" if x}".freeze]
17-
end
18-
}.freeze
8+
CSS_ESCAPE = [*"\x01".."\x08", *"\x0A".."\x1F", "\x7F"]
9+
.product([*'0'..'9', *'a'..'f', *'A'..'F', "\t", ' ', nil])
10+
.each.with_object({ "\0" => "\uFFFD", '\\' => '\\\\', '"' => '\\"', "'" => "\\'" }) do |(c, x), h|
11+
h["#{c}#{x}".freeze] = "\\#{c.ord.to_s(16)}#{" #{x}" if x}".freeze
12+
end.freeze
1913

2014
private_constant :CSS_ESCAPE
2115

lib/sass/value/number/unit.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ module Unit
141141
'pixel density': %w[dpi dpcm dppx]
142142
}.freeze
143143

144-
TYPES_BY_UNIT = UNITS_BY_TYPE.invert
145-
.to_a
146-
.flat_map { |pair| pair[0].map { |key| [key, pair[1]] } }
147-
.to_h
144+
TYPES_BY_UNIT = UNITS_BY_TYPE.each.with_object({}) do |(key, values), hash|
145+
values.each do |value|
146+
hash[value] = key
147+
end
148+
end
148149

149150
module_function
150151

0 commit comments

Comments
 (0)