So if I understand you right then you are probably trying to map the value of the column back to the column name.
eg.If you have a table like
id, name, age
1, “Alice”, 25
2, “Bob” , 35
Then given row for id 2, if you have a Fixnum 35 you want to be able to get string “age”. Is that right?
I am not a Rails expert but you could perhaps use column_names method on AR.
your bar could look like
def bar(active_record, value)
active_record.attribute_names.each do |x|
return active_record.column_for_attribute(x).name if active_record[x] == value
and call it with bar(@user, @user.age) as in your example.
There is a big caveat though and that is since we are comparing values
there could be more than one column of the same value and this snippet
matches the first match.
Without going into specifics of what you need you should perhaps look
for some alternate approach which could come from your domain use case.