NoMethod - Undefined method error even if the method has been definedUndefined method `%' for nil:NilClass (NoMethodError)“undefined method `valid?'” in chapter 10 of Michael Hartl's tutorialNo Method Error Rails(Method is there)RSpec undefined method “errors_on”Rspec POST results in undefined method `key?' for :create:SymbolExecution Flow in RubyWhere is undefined method called?Action Controller: Exception | undefined method `fetch_value' for nil:NilClassUndefined local variable or method error RubyRSpec error: undefined method `include?' for nil:NilClass & undefined method `downcase' for nil:NilClass

Company threatening to call my current job after I declined their offer

How did researchers find articles before the Internet and the computer era?

What is "oversubscription" in Networking?

Handling a player (unintentionally) stealing the spotlight

How to define a macro inside a macro via if?

Most important new papers in computational complexity

Can one use the present progressive or gerund like an adjective?

How receiver knows the exact frequency in the channel to "listen to"?

How to plan the font size in a fiction?

How can a valley surrounded by mountains be fertile and rainy?

What happens to a wizard's magic when they are swallowed by a tarrasque?

What game is this character in the Pixels movie from?

Resolve this Fibonacci Relationship

How to securely dispose of a smartphone?

Why were the first airplanes "backwards"?

Can you actually break an FPGA by programming it wrong?

Using the ArcGIS 'select by location' tool in ModelBuilder?

Can SOCPs approximate better than LPs?

What is "override advice"?

How to get a character's limb regrown at 3rd level?

Who voices the character "Finger" in The Fifth Element?

Why does the recording about Twin Pines Mall not change the same way the newspapers and photographs change?

How do we separate rules of logic from non-logical constraints?

What kind of jet plane is this?



NoMethod - Undefined method error even if the method has been defined


Undefined method `%' for nil:NilClass (NoMethodError)“undefined method `valid?'” in chapter 10 of Michael Hartl's tutorialNo Method Error Rails(Method is there)RSpec undefined method “errors_on”Rspec POST results in undefined method `key?' for :create:SymbolExecution Flow in RubyWhere is undefined method called?Action Controller: Exception | undefined method `fetch_value' for nil:NilClassUndefined local variable or method error RubyRSpec error: undefined method `include?' for nil:NilClass & undefined method `downcase' for nil:NilClass






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-4















I'm getting a no method - method undefined error while I am defining a method AFTER a particular method ends. The method defined before this one has an if..else statement block which might be creating an issue here



I've tried defining the mentioned method before the "problem making method" and in that case, my method works properly. But if any method is defined after that particular method, I get the same error message.



def display_board(board)
puts " #board[0] | #board[1] | #board[2] "
puts "-----------"
puts " #board[3] | #board[4] | #board[5] "
puts "-----------"
puts " #board[6] | #board[7] | #board[8] "
end
def input_to_index(pos)
pos = pos.to_i - 1
end

def valid_move?(board, pos)
if pos.between?(0,8)
if board[pos] == " "
return true
else
return false
end
else
return false
end
def move(board, pos, type)
board[pos] = "#type"
end
end


It should ideally pass all the test cases. But I'm getting this particular error:



1) ./lib/turn.rb #move allows "X" player in the bottom right and "O" in the top left
Failure/Error: move(board, 0, "O")
NoMethodError:
undefined method `move' for #<RSpec::ExampleGroups::LibTurnRb::Move:0x0000000001db90d8>
# ./spec/turn_spec.rb:70:in `block (3 levels) in <top (required)>'









share|improve this question

















  • 2





    If you indent your code properly, issues like this are much easier to understand.

    – Tom Lord
    Mar 25 at 16:14











  • @TomLord I'm agree!

    – Nifriz
    Mar 25 at 16:38











  • I agree too, apologies and thank you very much!

    – dslisanoob
    Mar 27 at 15:44

















-4















I'm getting a no method - method undefined error while I am defining a method AFTER a particular method ends. The method defined before this one has an if..else statement block which might be creating an issue here



I've tried defining the mentioned method before the "problem making method" and in that case, my method works properly. But if any method is defined after that particular method, I get the same error message.



def display_board(board)
puts " #board[0] | #board[1] | #board[2] "
puts "-----------"
puts " #board[3] | #board[4] | #board[5] "
puts "-----------"
puts " #board[6] | #board[7] | #board[8] "
end
def input_to_index(pos)
pos = pos.to_i - 1
end

def valid_move?(board, pos)
if pos.between?(0,8)
if board[pos] == " "
return true
else
return false
end
else
return false
end
def move(board, pos, type)
board[pos] = "#type"
end
end


It should ideally pass all the test cases. But I'm getting this particular error:



1) ./lib/turn.rb #move allows "X" player in the bottom right and "O" in the top left
Failure/Error: move(board, 0, "O")
NoMethodError:
undefined method `move' for #<RSpec::ExampleGroups::LibTurnRb::Move:0x0000000001db90d8>
# ./spec/turn_spec.rb:70:in `block (3 levels) in <top (required)>'









share|improve this question

















  • 2





    If you indent your code properly, issues like this are much easier to understand.

    – Tom Lord
    Mar 25 at 16:14











  • @TomLord I'm agree!

    – Nifriz
    Mar 25 at 16:38











  • I agree too, apologies and thank you very much!

    – dslisanoob
    Mar 27 at 15:44













-4












-4








-4








I'm getting a no method - method undefined error while I am defining a method AFTER a particular method ends. The method defined before this one has an if..else statement block which might be creating an issue here



I've tried defining the mentioned method before the "problem making method" and in that case, my method works properly. But if any method is defined after that particular method, I get the same error message.



def display_board(board)
puts " #board[0] | #board[1] | #board[2] "
puts "-----------"
puts " #board[3] | #board[4] | #board[5] "
puts "-----------"
puts " #board[6] | #board[7] | #board[8] "
end
def input_to_index(pos)
pos = pos.to_i - 1
end

def valid_move?(board, pos)
if pos.between?(0,8)
if board[pos] == " "
return true
else
return false
end
else
return false
end
def move(board, pos, type)
board[pos] = "#type"
end
end


It should ideally pass all the test cases. But I'm getting this particular error:



1) ./lib/turn.rb #move allows "X" player in the bottom right and "O" in the top left
Failure/Error: move(board, 0, "O")
NoMethodError:
undefined method `move' for #<RSpec::ExampleGroups::LibTurnRb::Move:0x0000000001db90d8>
# ./spec/turn_spec.rb:70:in `block (3 levels) in <top (required)>'









share|improve this question














I'm getting a no method - method undefined error while I am defining a method AFTER a particular method ends. The method defined before this one has an if..else statement block which might be creating an issue here



I've tried defining the mentioned method before the "problem making method" and in that case, my method works properly. But if any method is defined after that particular method, I get the same error message.



def display_board(board)
puts " #board[0] | #board[1] | #board[2] "
puts "-----------"
puts " #board[3] | #board[4] | #board[5] "
puts "-----------"
puts " #board[6] | #board[7] | #board[8] "
end
def input_to_index(pos)
pos = pos.to_i - 1
end

def valid_move?(board, pos)
if pos.between?(0,8)
if board[pos] == " "
return true
else
return false
end
else
return false
end
def move(board, pos, type)
board[pos] = "#type"
end
end


It should ideally pass all the test cases. But I'm getting this particular error:



1) ./lib/turn.rb #move allows "X" player in the bottom right and "O" in the top left
Failure/Error: move(board, 0, "O")
NoMethodError:
undefined method `move' for #<RSpec::ExampleGroups::LibTurnRb::Move:0x0000000001db90d8>
# ./spec/turn_spec.rb:70:in `block (3 levels) in <top (required)>'






ruby






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 14:08









dslisanoobdslisanoob

12 bronze badges




12 bronze badges







  • 2





    If you indent your code properly, issues like this are much easier to understand.

    – Tom Lord
    Mar 25 at 16:14











  • @TomLord I'm agree!

    – Nifriz
    Mar 25 at 16:38











  • I agree too, apologies and thank you very much!

    – dslisanoob
    Mar 27 at 15:44












  • 2





    If you indent your code properly, issues like this are much easier to understand.

    – Tom Lord
    Mar 25 at 16:14











  • @TomLord I'm agree!

    – Nifriz
    Mar 25 at 16:38











  • I agree too, apologies and thank you very much!

    – dslisanoob
    Mar 27 at 15:44







2




2





If you indent your code properly, issues like this are much easier to understand.

– Tom Lord
Mar 25 at 16:14





If you indent your code properly, issues like this are much easier to understand.

– Tom Lord
Mar 25 at 16:14













@TomLord I'm agree!

– Nifriz
Mar 25 at 16:38





@TomLord I'm agree!

– Nifriz
Mar 25 at 16:38













I agree too, apologies and thank you very much!

– dslisanoob
Mar 27 at 15:44





I agree too, apologies and thank you very much!

– dslisanoob
Mar 27 at 15:44












2 Answers
2






active

oldest

votes


















3














You have to close your valid_move? method before declare a new method (move)...



def valid_move?(board, pos)
if pos.between?(0,8)
if board[pos] == " "
return true
else
return false
end
else
return false
end
end

def move(board, pos, type)
board[pos] = "#type"
end


If you declare move method inside another method, is not visible in the main program.






share|improve this answer
































    0














    your move defined in valide_move? maybe try a better code editor prettifying. :)



    def valid_move?(board, pos)
    if pos.between?(0,8)
    if board[pos] == " "
    return true
    else
    return false
    end
    else
    return false
    end

    def move()
    board[pos] = "#type"
    puts "a"
    end
    end





    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55339716%2fnomethod-undefined-method-method-name-error-even-if-the-method-has-been-defi%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      You have to close your valid_move? method before declare a new method (move)...



      def valid_move?(board, pos)
      if pos.between?(0,8)
      if board[pos] == " "
      return true
      else
      return false
      end
      else
      return false
      end
      end

      def move(board, pos, type)
      board[pos] = "#type"
      end


      If you declare move method inside another method, is not visible in the main program.






      share|improve this answer





























        3














        You have to close your valid_move? method before declare a new method (move)...



        def valid_move?(board, pos)
        if pos.between?(0,8)
        if board[pos] == " "
        return true
        else
        return false
        end
        else
        return false
        end
        end

        def move(board, pos, type)
        board[pos] = "#type"
        end


        If you declare move method inside another method, is not visible in the main program.






        share|improve this answer



























          3












          3








          3







          You have to close your valid_move? method before declare a new method (move)...



          def valid_move?(board, pos)
          if pos.between?(0,8)
          if board[pos] == " "
          return true
          else
          return false
          end
          else
          return false
          end
          end

          def move(board, pos, type)
          board[pos] = "#type"
          end


          If you declare move method inside another method, is not visible in the main program.






          share|improve this answer















          You have to close your valid_move? method before declare a new method (move)...



          def valid_move?(board, pos)
          if pos.between?(0,8)
          if board[pos] == " "
          return true
          else
          return false
          end
          else
          return false
          end
          end

          def move(board, pos, type)
          board[pos] = "#type"
          end


          If you declare move method inside another method, is not visible in the main program.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 25 at 14:20

























          answered Mar 25 at 14:13









          NifrizNifriz

          4151 gold badge3 silver badges14 bronze badges




          4151 gold badge3 silver badges14 bronze badges























              0














              your move defined in valide_move? maybe try a better code editor prettifying. :)



              def valid_move?(board, pos)
              if pos.between?(0,8)
              if board[pos] == " "
              return true
              else
              return false
              end
              else
              return false
              end

              def move()
              board[pos] = "#type"
              puts "a"
              end
              end





              share|improve this answer



























                0














                your move defined in valide_move? maybe try a better code editor prettifying. :)



                def valid_move?(board, pos)
                if pos.between?(0,8)
                if board[pos] == " "
                return true
                else
                return false
                end
                else
                return false
                end

                def move()
                board[pos] = "#type"
                puts "a"
                end
                end





                share|improve this answer

























                  0












                  0








                  0







                  your move defined in valide_move? maybe try a better code editor prettifying. :)



                  def valid_move?(board, pos)
                  if pos.between?(0,8)
                  if board[pos] == " "
                  return true
                  else
                  return false
                  end
                  else
                  return false
                  end

                  def move()
                  board[pos] = "#type"
                  puts "a"
                  end
                  end





                  share|improve this answer













                  your move defined in valide_move? maybe try a better code editor prettifying. :)



                  def valid_move?(board, pos)
                  if pos.between?(0,8)
                  if board[pos] == " "
                  return true
                  else
                  return false
                  end
                  else
                  return false
                  end

                  def move()
                  board[pos] = "#type"
                  puts "a"
                  end
                  end






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 14:17









                  Pan KePan Ke

                  5497 bronze badges




                  5497 bronze badges



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55339716%2fnomethod-undefined-method-method-name-error-even-if-the-method-has-been-defi%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현