Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

401
Views
Ruby Method definition Syntax with & keyword
class ExchangeUtil
  def exchange_to(other_currency, date = Date.current, &)
      @bank.exchange_with_on(self, other_currency, date, &)
  end
end

What is the siginificance of & in method definition and method calls?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It's a new feature in Ruby 3.1: Anonymous block argument

It's just a shortcut for when you have a block argument for a function whose only purpose is to be passed to another function. Older syntax for that would've been

class ExchangeUtil
  def exchange_to(other_currency, date = Date.current, &block)
      @bank.exchange_with_on(self, other_currency, date, &block)
  end
end

The param &block could've had any name, like &my_block, but the name was generally meaningless, so they made it "anonymous".

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!