1

I want to add "*" to the object. So I was thinking to do something like

  def initialize(search:)
    @search = search + "*"
  end

it works but I think this is not quite elegant way to do it. What is the better, more efficient way?

4
  • 4
    @search = "#{search} *" that can works Commented Oct 17, 2019 at 13:04
  • Why do you want to / have to add *? Commented Oct 17, 2019 at 13:12
  • @Stefan to search more precisely Commented Oct 17, 2019 at 13:52
  • In that case I'd just store the search term and append * when actually executing the search. Commented Oct 17, 2019 at 15:20

2 Answers 2

3

I'd recommend you to do it this way

@search = "#{search}*"
Sign up to request clarification or add additional context in comments.

Comments

1

The The Ruby Style Guide says these are ok:

@search = "#{search}*"

or

@search = format('%s%s', search, "*")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.