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;
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
add a comment |
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
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
add a comment |
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
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
ruby
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
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
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 25 at 14:17
Pan KePan Ke
5497 bronze badges
5497 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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