Thursday, 15 April 2010

ruby - Rails runner throwing "undefined local variable or method" error for simple script -


When we ask for this order, rail runner test.rb -e production , we get this error Let's see:

  test.rb: 2: `at the top (required) & gt; ':' Hello 'for undefined local variable or method main: object (name entered) / usr / local / Lib / ruby ​​/ gemstone / 1.9.1 / gemstone / railway-3.2.22 / lib / rail / order / Runner RB: 51: `/ ev / Gem / Railway-3.2.12 / Leib / Rail / Order / Runner RB: 51: `At the top (required) & gt; /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in From / usr / local / lib / ruby ​​/ gemma / ' Required '1.9.1 / gemstone / railways -3.2.12 / Leib / Rail / Command. RB: 64: `Top (required) & gt; Script / Rail: 6: In 'Required' from Script / Rail: 6: `& lt; Main & gt; '  

Content of test.rb:

  Hello Diff hello puts "hi" and   

Why this Happening ? We are at Rail 3.2.12.

  Hello # delete it Deaf hello "hi" puts the end  < / Pre> 

See introspection:

  defined? Hello # = & gt; Zero # So here Ruby does not know who is "Hello", and throws this error from Hello to your def def hello say "hi" defined end? Hello # = & gt; "Method" Hello # = & gt; "Hello"    

No comments:

Post a Comment