Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8281047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:53:58+00:00 2026-06-08T09:53:58+00:00

I have confusion for using expression interpolation in method. Initially I thought I can

  • 0

I have confusion for using expression interpolation in method. Initially I thought I can pass any kind of expression like let’s say name.capitalize, but I can pass without expression interpolation too. Here is the two cases. Just execute below two methods on irb, I have same result for both method. I am using Ruby 1.9.3

1.

def say_goodnight(name)
 result = "Good night, " + name.capitalize
 return result
end

puts say_goodnight('uncle')

2.

def say_goodnight(name)
  result = "Good night, #{name.capitalize}"
  return result
end

puts say_goodnight('uncle')

Both way it will produce output like

Good night, Uncle

So my question is When Should I use expression interpolation in Ruby? and When Should I use parameter in Ruby?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:54:00+00:00Added an answer on June 8, 2026 at 9:54 am

    Whichever reads cleaner is generally better. For example, if the string contains a number of variable references, each separated by a few characters, the “+” form of the expression can become complex and unclear, while an interpolated string is more obvious. On the other hand, if the expression(s) are relatively complex, it’s better to separate them from other components of the string.

    So, I think the following:

    "Hello #{yourname}, my name is #{myname} and I'm #{mood} to see you."
    

    is clearer than

    "Hello " + yourname + ", my name is " + myname + " and I'm " + mood + "to see you."
    

    But if I had complex expressions, I might want to separate those onto different source code lines, and those are better connected with “+”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One thing I have continually found very confusing about using an object database like
I have a confusion regarding DataContext which i would like someone to confirm or
I am using a backgroundworker that can have n instances. Problem is the DoWork
I have been developing many application and have been into confusion about using dataset.
I am new to XSL and I have a confusion whether we can read
How can I replace/append something (22) string to something , using some kind of
First, I have to say that I really like Groovy and all the good
I have a confusion about ImageButton . I can make an ImageView clickable and
I have a small confusion with the IDisposable interface and the using keyword in
I have used the web client method to download images using a background worker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.