1

I have a method in application_helper:

def methodname(argument)
 if "XXXX".match(/#{argument}/i).present?
 puts "YYYY"
else
end

And in console:

require "#{Rails.root}/app/helpers/application_helper"
=> true
include ApplicationHelper
=> Object
> methodname("argument")
YYYY=> nil
> loremipsum = methodname("argument")
YYYY=> nil
> loremipsum
=> nil

So it returns YYYY which is correct but it also returns nil for some reason beyond my understanding. I only need YYYY. How can I "extract" / use it? I would like:

> somemagicalcommand
> "YYYY"

:)

TIA!

1 Answer 1

1

You are using the puts function, which outputs something on the console, like a printf on C, or System.out.printf in Java.

If instead of using puts you return the value, I think you may have the result you're looking for :).

def methodname(argument) return "YYYY" if "XXXX".match(/#{argument}/i).present? end

Sign up to request clarification or add additional context in comments.

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.