Skip to content

Commit

Permalink
Update inspect output of ActionController::Parameters in docs [skip-ci]
Browse files Browse the repository at this point in the history
In 74cb9a6 a `#` was added to the
inspect of ActionController::Parameters.
This change adds `#` to the inspect output of
ActionController::Parameters in the documentation.
  • Loading branch information
p8 committed Nov 23, 2021
1 parent f132be4 commit 9ee8b08
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Expand Up @@ -81,7 +81,7 @@ def initialize # :nodoc:
# })
#
# permitted = params.require(:person).permit(:name, :age)
# permitted # => <ActionController::Parameters {"name"=>"Francesco", "age"=>22} permitted: true>
# permitted # => #<ActionController::Parameters {"name"=>"Francesco", "age"=>22} permitted: true>
# permitted.permitted? # => true
#
# Person.first.update!(permitted)
Expand Down Expand Up @@ -111,7 +111,7 @@ def initialize # :nodoc:
#
# params = ActionController::Parameters.new(a: "123", b: "456")
# params.permit(:c)
# # => <ActionController::Parameters {} permitted: true>
# # => #<ActionController::Parameters {} permitted: true>
#
# ActionController::Parameters.action_on_unpermitted_parameters = :raise
#
Expand Down Expand Up @@ -442,7 +442,7 @@ def permit!
# either present or the singleton +false+, returns said value:
#
# ActionController::Parameters.new(person: { name: "Francesco" }).require(:person)
# # => <ActionController::Parameters {"name"=>"Francesco"} permitted: false>
# # => #<ActionController::Parameters {"name"=>"Francesco"} permitted: false>
#
# Otherwise raises <tt>ActionController::ParameterMissing</tt>:
#
Expand Down Expand Up @@ -570,13 +570,13 @@ def require(key)
# })
#
# params.require(:person).permit(:contact)
# # => <ActionController::Parameters {} permitted: true>
# # => #<ActionController::Parameters {} permitted: true>
#
# params.require(:person).permit(contact: :phone)
# # => <ActionController::Parameters {"contact"=><ActionController::Parameters {"phone"=>"555-1234"} permitted: true>} permitted: true>
# # => #<ActionController::Parameters {"contact"=>#<ActionController::Parameters {"phone"=>"555-1234"} permitted: true>} permitted: true>
#
# params.require(:person).permit(contact: [ :email, :phone ])
# # => <ActionController::Parameters {"contact"=><ActionController::Parameters {"email"=>"none@test.com", "phone"=>"555-1234"} permitted: true>} permitted: true>
# # => #<ActionController::Parameters {"contact"=>#<ActionController::Parameters {"email"=>"none@test.com", "phone"=>"555-1234"} permitted: true>} permitted: true>
#
# If your parameters specify multiple parameters indexed by a number,
# you can permit each set of parameters under the numeric key to be the same using the same syntax as permitting a single item.
Expand Down Expand Up @@ -633,7 +633,7 @@ def permit(*filters)
# returns +nil+.
#
# params = ActionController::Parameters.new(person: { name: "Francesco" })
# params[:person] # => <ActionController::Parameters {"name"=>"Francesco"} permitted: false>
# params[:person] # => #<ActionController::Parameters {"name"=>"Francesco"} permitted: false>
# params[:none] # => nil
def [](key)
convert_hashes_to_parameters(key, @parameters[key])
Expand All @@ -653,9 +653,9 @@ def []=(key, value)
# is given, then that will be run and its result returned.
#
# params = ActionController::Parameters.new(person: { name: "Francesco" })
# params.fetch(:person) # => <ActionController::Parameters {"name"=>"Francesco"} permitted: false>
# params.fetch(:person) # => #<ActionController::Parameters {"name"=>"Francesco"} permitted: false>
# params.fetch(:none) # => ActionController::ParameterMissing: param is missing or the value is empty: none
# params.fetch(:none, {}) # => <ActionController::Parameters {} permitted: false>
# params.fetch(:none, {}) # => #<ActionController::Parameters {} permitted: false>
# params.fetch(:none, "Francesco") # => "Francesco"
# params.fetch(:none) { "Francesco" } # => "Francesco"
def fetch(key, *args)
Expand Down Expand Up @@ -689,8 +689,8 @@ def dig(*keys)
# don't exist, returns an empty hash.
#
# params = ActionController::Parameters.new(a: 1, b: 2, c: 3)
# params.slice(:a, :b) # => <ActionController::Parameters {"a"=>1, "b"=>2} permitted: false>
# params.slice(:d) # => <ActionController::Parameters {} permitted: false>
# params.slice(:a, :b) # => #<ActionController::Parameters {"a"=>1, "b"=>2} permitted: false>
# params.slice(:d) # => #<ActionController::Parameters {} permitted: false>
def slice(*keys)
new_instance_with_inherited_permitted_status(@parameters.slice(*keys))
end
Expand All @@ -706,17 +706,17 @@ def slice!(*keys)
# filters out the given +keys+.
#
# params = ActionController::Parameters.new(a: 1, b: 2, c: 3)
# params.except(:a, :b) # => <ActionController::Parameters {"c"=>3} permitted: false>
# params.except(:d) # => <ActionController::Parameters {"a"=>1, "b"=>2, "c"=>3} permitted: false>
# params.except(:a, :b) # => #<ActionController::Parameters {"c"=>3} permitted: false>
# params.except(:d) # => #<ActionController::Parameters {"a"=>1, "b"=>2, "c"=>3} permitted: false>
def except(*keys)
new_instance_with_inherited_permitted_status(@parameters.except(*keys))
end

# Removes and returns the key/value pairs matching the given keys.
#
# params = ActionController::Parameters.new(a: 1, b: 2, c: 3)
# params.extract!(:a, :b) # => <ActionController::Parameters {"a"=>1, "b"=>2} permitted: false>
# params # => <ActionController::Parameters {"c"=>3} permitted: false>
# params.extract!(:a, :b) # => #<ActionController::Parameters {"a"=>1, "b"=>2} permitted: false>
# params # => #<ActionController::Parameters {"c"=>3} permitted: false>
def extract!(*keys)
new_instance_with_inherited_permitted_status(@parameters.extract!(*keys))
end
Expand All @@ -726,7 +726,7 @@ def extract!(*keys)
#
# params = ActionController::Parameters.new(a: 1, b: 2, c: 3)
# params.transform_values { |x| x * 2 }
# # => <ActionController::Parameters {"a"=>2, "b"=>4, "c"=>6} permitted: false>
# # => #<ActionController::Parameters {"a"=>2, "b"=>4, "c"=>6} permitted: false>
def transform_values
return to_enum(:transform_values) unless block_given?
new_instance_with_inherited_permitted_status(
Expand Down

0 comments on commit 9ee8b08

Please sign in to comment.