Skip to content

Commit

Permalink
No more Object#send, using Object#public_send instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmestad committed Jun 5, 2018
1 parent 1312c03 commit 41fb49e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/jsonapi/consumer/helpers/dynamic_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def attributes=(attrs = {})

return @attributes unless attrs.present?
attrs.each do |key, value|
send("#{key}=", value)
public_send("#{key}=", value)
end
end

Expand Down Expand Up @@ -44,7 +44,7 @@ def method_missing(method, *args, &block)
attributes[method]
end
end
return send(method)
return public_send(method)
end

normalized_method = safe_key_formatter.unformat(method.to_s)
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi/consumer/query/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def find(args = {})
end

def method_missing(method_name, *args, &block)
to_a.send(method_name, *args, &block)
to_a.public_send(method_name, *args, &block)
end

private
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ def with_altered_config(resource_class, changes)
old_config_values = {}
changes.each_pair do |key, value|
old_config_values[key] = resource_class.send(key)
resource_class.send("#{key}=", value)
resource_class.public_send("#{key}=", value)
end

yield

# restore config
old_config_values.each_pair do |key, value|
resource_class.send("#{key}=", old_config_values[key])
resource_class.public_send("#{key}=", old_config_values[key])
end
end
4 changes: 2 additions & 2 deletions test/unit/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def test_formatted_key_accessors
article = Article.new("foo-bam" => "baz")
# Does not recognize dasherized attributes, fall back to hash syntax
refute article.respond_to? :foo_bam
assert_equal("baz", article.send("foo-bam"))
assert_equal("baz", article.send(:"foo-bam"))
assert_equal("baz", article.public_send("foo-bam"))
assert_equal("baz", article.public_send(:"foo-bam"))
assert_equal("baz", article["foo-bam"])
assert_equal("baz", article[:"foo-bam"])
end
Expand Down

0 comments on commit 41fb49e

Please sign in to comment.