@@ -26,12 +26,12 @@ def self.encode(*args, &block)
26
26
BLANK = Blank . new
27
27
NON_ENUMERABLES = [ ::Struct , ::OpenStruct ] . to_set
28
28
29
- def set! ( key , value = BLANK , *args )
29
+ def set! ( key , value = BLANK , *args , & block )
30
30
result = if ::Kernel . block_given?
31
31
if !_blank? ( value )
32
32
# json.comments @post.comments { |comment| ... }
33
33
# { "comments": [ { ... }, { ... } ] }
34
- _scope { array! value , &:: Proc . new }
34
+ _scope { array! value , &block }
35
35
else
36
36
# json.comments { ... }
37
37
# { "comments": ... }
@@ -61,9 +61,9 @@ def set!(key, value = BLANK, *args)
61
61
_set_value key , result
62
62
end
63
63
64
- def method_missing ( *args )
64
+ def method_missing ( *args , & block )
65
65
if ::Kernel . block_given?
66
- set! ( *args , &:: Proc . new )
66
+ set! ( *args , &block )
67
67
else
68
68
set! ( *args )
69
69
end
@@ -181,11 +181,11 @@ def child!
181
181
# json.array! [1, 2, 3]
182
182
#
183
183
# [1,2,3]
184
- def array! ( collection = [ ] , *attributes )
184
+ def array! ( collection = [ ] , *attributes , & block )
185
185
array = if collection . nil?
186
186
[ ]
187
187
elsif ::Kernel . block_given?
188
- _map_collection ( collection , &:: Proc . new )
188
+ _map_collection ( collection , &block )
189
189
elsif attributes . any?
190
190
_map_collection ( collection ) { |element | extract! element , *attributes }
191
191
else
@@ -220,9 +220,9 @@ def extract!(object, *attributes)
220
220
end
221
221
end
222
222
223
- def call ( object , *attributes )
223
+ def call ( object , *attributes , & block )
224
224
if ::Kernel . block_given?
225
- array! object , &:: Proc . new
225
+ array! object , &block
226
226
else
227
227
extract! object , *attributes
228
228
end
0 commit comments