例如:
class Student
attr_accessor :name
def initialize(name)
@name=name
end
end
s1 = Student.new("student1")
var = "name"
puts s1.var # error message, var is not defined in class Student
我希望puts s1.var
像puts s1.name
一样打印“ student1”