sorry if i misunderstood what you wanted to do from your first post…
“…asks for input and we give it ‘hello’, function creates a variable
called x and sets equal to ‘hello’. We now have an x variable with a
value for use at later time.”
as 7stud pointed out, my suggestion doesn’t take an argument, but does
set the “x variable” to an instance variable with the value of the user
@x = gets.chomp!
if you want to give #foo an argument, have that made an instance
variable, and be able to change the “x variable,” you could do something
@x = x
@x = " "
input = gets.chomp!
your last post leads me to think that you don’t want the argument to
#foo set to the “x variable,” but that you want the argument itself to
become an instance variable. if that’s the case, then maybe something
like this is what you’re looking for:
input = gets.chomp! #input will have to start with “@”
or set both the variable and the value from user input:
irb(main):001:0> ivar = gets.chomp!
irb(main):002:0> value = gets.chomp!
irb(main):003:0> instance_variable_set(ivar, value)
irb(main):004:0> puts @bar