Having a very simple method saved in test.rb
:
def say_good_night(name)
result = "Good night, #{name}"
puts result
end
How can I pass a variable to this method through terminal?
My initial thought was test.rb say_good_night("Johny)
Having a very simple method saved in test.rb
:
def say_good_night(name)
result = "Good night, #{name}"
puts result
end
How can I pass a variable to this method through terminal?
My initial thought was test.rb say_good_night("Johny)
ARGV
is an array of string variables passed to your script. So
def say_good_night(name)
result = "Good night, #{name}"
puts result
end
say_good_night(ARGV[0])
or even
ARGV.each { |name| say_good_night(name) }
and call it as
ruby test.rb KOFI_113