question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in lambda creation: in 'lambda': tried to create Proc object without a block (ArgumentError)

See original GitHub issue

Input

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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kddnewtoncommented, Feb 14, 2019

Fixed by #99

1reaction
kddnewtoncommented, Feb 11, 2019

Thanks for the report! I’ll check it out.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found