Skip to content

Commit

Permalink
activerecord: AR::Relation#new should take block argument as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Sep 8, 2024
1 parent e9bc1bf commit c122217
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
14 changes: 0 additions & 14 deletions gems/activerecord/6.0/activerecord-generated.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -19265,20 +19265,6 @@ module ActiveRecord

def bind_attribute: (untyped name, untyped value) { (untyped, untyped) -> untyped } -> untyped

# Initializes new record from relation while maintaining the current
# scope.
#
# Expects arguments in the same format as {ActiveRecord::Base.new}[rdoc-ref:Core.new].
#
# users = User.where(name: 'DHH')
# user = users.new # => #<User id: nil, name: "DHH", created_at: nil, updated_at: nil>
#
# You can also pass a block to new with the new record as argument:
#
# user = users.new { |user| user.name = 'Oscar' }
# user.name # => Oscar
def new: (?untyped? attributes) { () -> untyped } -> untyped

alias build new

# Tries to create a new record with the same scoped attributes
Expand Down
18 changes: 18 additions & 0 deletions gems/activerecord/6.0/activerecord.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,24 @@ module ActiveRecord
end
end

module ActiveRecord
class Relation
# Initializes new record from relation while maintaining the current
# scope.
#
# Expects arguments in the same format as {ActiveRecord::Base.new}[rdoc-ref:Core.new].
#
# users = User.where(name: 'DHH')
# user = users.new # => #<User id: nil, name: "DHH", created_at: nil, updated_at: nil>
#
# You can also pass a block to new with the new record as argument:
#
# user = users.new { |user| user.name = 'Oscar' }
# user.name # => Oscar
def new: (?untyped? attributes) ?{ () -> untyped } -> untyped
end
end

module ActiveRecord
class Relation
module Methods[Model, PrimaryKey]
Expand Down

0 comments on commit c122217

Please sign in to comment.