You cannot evaluate a JavaScript variable inside your Ruby method. In addition, your current script should be outside the asset pipeline, which is usually bad practice.
One simple solution is to pass the variable as a data attribute. You will run your method and then pass the result using jQuery after loading the DOM. This allows you to store JavaScript in the asset pipeline and pass its data evaluated by the Ruby server.
: @b :
<div id="foo" data-bar="<%= method.a(@b).to_s %>"></div>
<script>
$(document).ready(function() {
var b = $(
var c = "string" + b;
});
</script>
, script JavaScript Rails.