Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't this extension method work in Rails?
    text
    copied!<p>In config/initializers:</p> <p>Created file numeric_helper.rb:</p> <pre><code> class Numeric def my_function self + 1 end end </code></pre> <p><code>rails console</code> throws </p> <pre><code>/home/baller/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in `load': /home/baller/rails/big_pimpin/config/initializers/numeric_helper.rb:1: syntax error, unexpected keyword_def, expecting '&lt;' or ';' or '\n' (SyntaxError) endss Nuend my_fself + 1 </code></pre> <p>Why does this throw an error?</p> <p>Working in Rails 3.07.</p> <p>EDIT: The rest of the error trace:</p> <pre><code>from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in 'block in load' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in 'block in load_dependency' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in 'new_constants_in' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in 'load_dependency' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in 'load' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/engine.rb:201:in 'block (2 levels) in &lt;class:Engine&gt;' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/engine.rb:200:in 'each' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/engine.rb:200:in 'block in &lt;class:Engine&gt;' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/initializable.rb:25:in 'instance_exec' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/initializable.rb:25:in 'run' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/initializable.rb:50:in 'block in run_initializers' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/initializable.rb:49:in 'each' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/initializable.rb:49:in 'run_initializers' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/application.rb:134:in 'initialize!' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/application.rb:77:in 'method_missing' from /home/baller/rails/fann/config/environment.rb:5:in '&lt;top (required)&gt;' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/application.rb:103:in 'require' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/application.rb:103:in 'require_environment!' from /home/baller/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.7/lib/rails/commands.rb:22:in '&lt;top (required)&gt;' from script/rails:6:in 'require' from script/rails:6:in '&lt;main&gt;' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload