动态设置ruby变量
p "Enter a variable name" x = "@" + gets.chomp! instance_variable_set x, 42 p "The value of #{x} is #{instance_variable_get x}"
Example output:
"Enter a variable name" hello "The value of @hello is 42"
阅读量: 836
发布于:
修改于:
发布于:
修改于:
p "Enter a variable name" x = "@" + gets.chomp! instance_variable_set x, 42 p "The value of #{x} is #{instance_variable_get x}"
"Enter a variable name" hello "The value of @hello is 42"