Error in lambda creation: in 'lambda': tried to create Proc object without a block (ArgumentError)
See original GitHub issueInput
scope :sorted, -> { order("#{table_name}.priority desc, #{table_name}.sort_order ASC, #{table_name}.name asc") }
Current output
scope :sorted,
lambda do
order(
"#{table_name}.priority desc, #{table_name}.sort_order ASC, #{table_name}.name asc"
)
end
Running rails s
generates this error: app/models/temp.rb:252:in 'lambda': tried to create Proc object without a block (ArgumentError)
Expected output
scope :sorted,
(lambda do
order(
"#{table_name}.priority desc, #{table_name}.sort_order ASC, #{table_name}.name asc"
)
end)
Or maybe (tho this gets Rubocop yelling at me):
scope :sorted,
-> {
order(
"#{table_name}.priority desc, #{table_name}.sort_order ASC, #{table_name}.name asc"
)
}
This also affect when a Proc in a has_many
with traits afterwards:
has_many :staff, -> { where(staff_type: 2, users: { role: User::STAFF } ) }, through: users
becomes
has_many :staff,
lambda do
where(
staff_type: 2, users: { role: User::STAFF }
)
end,
through: :users
which returns (when run):
app/models/temp.rb:221: syntax error, unexpected ',', expecting keyword_end (SyntaxError)
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Scope but error message ArgumentError: tried to create Proc ...
Got error message ArgumentError: tried to create Proc object without a block when running command 'Contact. noaddress' in rails c.
Read more >Ruby 2.7 adds warning for Proc.new and proc without block ...
In Ruby 2.7 Proc.new and proc with no block in a method called with a block is warned now and lambda with no...
Read more >tried to create Proc object without a block (ArgumentError)-ruby
Coding example for the question in `lambda': tried to create Proc object without a block (ArgumentError)-ruby.
Read more >Proc | Ruby API (v3.1)
A Proc object is an encapsulation of a block of code, which can be stored in a local variable, passed to a method...
Read more >Proc.new Trick. Ruby's Proc.new without an explicit… - Medium
ArgumentError : tried to create Proc object without a block ... we haven't explicitly passed a block to Proc.new , Ruby raises no...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed by #99
Thanks for the report! I’ll check it out.