model Sample has attributes car,bike
x ="bike"
y = Sample.new
How can I do?
y.x ?? It gives me an error Is there any way I can do it, I know that x is an attribute but I dont know which one.
So how can I get y.x?
You can use send to invoke a method on an object when the method is stored as a string:
x = "bike"
y = Sample.new
y.send(x) # Equivalent to y.bike
The following are equivalent, except that you may send protected methods:
object.method_name
object.send("method_name")
object.send(:method_name)