Chaining your own method in Ruby on Rails

Posted by steven_noble on Stack Overflow See other posts from Stack Overflow or by steven_noble
Published on 2010-06-12T22:20:16Z Indexed on 2010/06/12 22:22 UTC
Read the original article Hit count: 128

Filed under:

In my Rails app, I am used to using syntax like the following in a number of places, including helpers/application_helper.rb:

def my_method(x,y)
  return x+y
end

I am also used to calling the resulting method from basically anywhere in my app using syntax like this:

my_method(2,3)

However, I'd like to be able to use syntax like like this:

class_from_my_rails_app.my_method(3)

How and where do I define my_method so I can use it like this?

I'm happy to consult the documentation, but I just don't know what the latter style is called. What do you call it?

Many thanks,

Steven.

© Stack Overflow or respective owner

Related posts about ruby-on-rails