Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:20:08+00:00 2026-06-17T06:20:08+00:00

I have a method that checks if a word includes a certain letter. The

  • 0

I have a method that checks if a word includes a certain letter. The string#include? method’s supposed to return true if the string object contains the letter in any position. However, my method is only returning true if there’s a match between the letter (char_clicked) and the letter at the first position of the word (final_word). For example, if the final_word parameter is Spain, the method is only returning true if “S” is the char_clicked, it’ll return false if char_clicked is any of “_pain”

Can you please ease my pain and tell me what I’m doing wrong…

def correct_guess?(char_clicked, final_word)
      puts char_clicked, final_word      #p, Spain  
      puts final_word.is_a?(String)      #true
      puts "checking if string"
      puts final_word.include?(char_clicked)  #false
  final_word.include?(char_clicked)
end

Update

I’m getting the same result even if I turn the string into an array and check for the letter

puts final_word.split("").include?(char_clicked)

However, if I use include in the console for that application, it works fine

>> s = "brazil"
=> "brazil"
>> s.include?("z")
=> true

Seeing as the first response to this question confirms that include? should be working the way I’ve shown it above, I’m providing more information which might hopefully explain why it’s not working as one would expect

The final_word is being pulled out of the session before being sent to the correct_guess? method for checking. The char_clicked is pulled out of the parameters

def check 
    final_word = session[:word]
    char_clicked = params[:char_clicked]
    correct_guess = Game.correct_guess?(char_clicked, final_word)
    ....

Ajax request sending the char_clicked to the above check method

$.ajax({
        url: "/check",
        type: "POST",
        data: {char_clicked: this.get("char_clicked")},
        success: function(response) {
          console.log(response);
          var json = $.parseJSON(response);

          if (response.incorrect_guesses >= _this.get("threshold")) _this.set({lost: true});
          if (response.win) _this.set({win: true});

          _this.trigger("guessCheckedEvent", response);
        }
      })
    },
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:20:10+00:00Added an answer on June 17, 2026 at 6:20 am

    Maybe include? is overridden somewhere (monkeypatched). Does the following work?

    def correct_guess?(char_clicked, final_word)
      final_word =~ /#{char_clicked}/i
    end
    

    It’s unlikely that the regex-matcher method is overridden, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that checks spots in a 2D array, and it also
i currently have a method that checks what is around the centre item in
I have method that returns Drawable , and if its Bitmap object is recycled
I have tried to fix a method that checks if the user has Skype
I have a method that takes a string value as a parameter and then
Is there a windows form textbox or c# string native member method that checks
I have a method that checks a JSON payload for JSON decoding errors, and
I have a method that checks if a thumbnail is validate for uploading. For
I have a Java method that looks for a word inside a phrase, and
So I have a method that checks if the device is connected to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.