ruby-on-railsmethod-names

Use @ symbol in a rails method name


Is there any way for me to use the '@' symbol in a rails method name? e.g.

def @method_name

end

Rails doesn't seem to like it.

I want to do it to adhere to some external conventions (external to rails).


Solution

  • It can be done like this:

    define_method('@test') do
      'test'
    end
    

    this method then has to be called with:

    model.send('@test')
    

    I would not recommend it, since it will be ugly and complicated and that is against the philosophy of ruby. But it can be done.

    Kind of like this video: https://www.youtube.com/watch?v=eVpVHGiELf8