Skip to content

Commit d0bfbd8

Browse files
committed
remove conditional that could sometimes instance_eval on current_object when passing a block with no args to #attribute
1 parent 7d4438e commit d0bfbd8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/bldr/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def attribute(*args,&block)
204204
if block_given?
205205
raise(ArgumentError, "You may only pass one argument to #attribute when using the block syntax.") if args.size > 1
206206
raise(ArgumentError, "You cannot use a block of arity > 0 if current_object is not present.") if block.arity > 0 and current_object.nil?
207-
merge_result!(args.first, (block.arity == 1) ? block.call(current_object) : current_object.instance_eval(&block))
207+
merge_result! args.first, block.call(current_object)
208208
else
209209
case args.size
210210
when 1 # inferred object

spec/fixtures/nested_objects.json.bldr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
object :person => bert do
33
attributes :name, :age
4-
attribute :name_age do
5-
"#{name} #{age}"
4+
attribute :name_age do |person|
5+
"#{person.name} #{person.age}"
66
end
77

88
object :friend => ernie do

0 commit comments

Comments
 (0)