1

If I try outside the controller it works:

using ParamsExtension
class ApplicationController

If I try inside the controller or an action it does not work:

class ApplicationController
using ParamsExtension

It throws 'undefined method `using'.

I read this article and the author is using it inside a class: timelessrepo.com/refinements-in-ruby

dgilperez
  • 10,716
  • 8
  • 68
  • 96
Jirico
  • 1,242
  • 1
  • 15
  • 29

2 Answers2

2

Based on this article, refinements within classes are only available on 2.3 and up.

Patrick C
  • 186
  • 9
1

I read the following from the documentation:

You may only activate refinements at top-level, not inside any class, module or method scope. You may activate refinements in a string passed to Kernel#eval that is evaluated at top-level. Refinements are active until the end of the file or the end of the eval string, respectively.

http://www.ruby-doc.org/core-2.1.1/doc/syntax/refinements_rdoc.html

Keith
  • 686
  • 5
  • 7
  • Interesting, but I read this article, the author is using it inside a class: http://timelessrepo.com/refinements-in-ruby – Jirico Jul 24 '14 at 19:18
  • What version of ruby are you using? In Ruby 2.0, the docs aren't as explicit about where the 'using' clause may be placed. Here are the 2.0 docs: http://ruby-doc.org/core-2.0.0/doc/syntax/refinements_rdoc.html – Keith Jul 24 '14 at 19:36
  • I'm using 2.0.0. I just read the doc in your comment and there is an example of 'using' inside a class: "You may also activate refinements in a class or module definition, in which case the refinements are activated from the point where using is called to the end of the class or module definition:" – Jirico Jul 24 '14 at 20:12