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

  • SEARCH
  • Home
  • 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 8807113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:17:34+00:00 2026-06-14T02:17:34+00:00

BACKGROUND I have a multidimensional hash which I want to perform a check to

  • 0

BACKGROUND

I have a multidimensional hash which I want to perform a check to ensure that the lookup found a match, but it does not seem to work the same as single dimension hash. My code works for a case where it finds a match, but not for a non-match. I have read posts in which under certain circumstances the hash will automatically generate a key for a non match, which I think will result in a NIL since I did not specifically set a value. The error message I get for a non-match case is:

can't convert Hash into String (TypeError)

Link to my project for context: https://github.com/elvisimprsntr/siriproxy-redeye

Excerpt of code and hyperlinks to source:

redeyeconfig.rb

# Channel number and command syntax to actual RedEye device commandIds
# Note: Must all be lower case. Use multiple entries for variability in Siri response.
@cmdId = Hash.new(&(p=lambda{|h,k| h[k] = Hash.new(&p)}))
@cmdId["all"]["cable box"]["0"]         = "/commands/send?commandId=3"
@cmdId["all"]["cable box"]["zero"]      = "/commands/send?commandId=3"
@cmdId["all"]["cable box"]["1"]         = "/commands/send?commandId=4"

siriproxy-redeye.rb

  def send_command(command)
    commandid = @cmdId[@reRoom][@reDevice][command.downcase.strip]
    unless commandid.nil?
        say "OK. Sending command #{command}."
# FIXIT: Does not properly handle no match.  Results in "can't convert Hash into String (TypeError)"
#   This may be due to the fact that dynamically created multidimensional hash will create new keys if a match is not found which will pass the NIL check.
        Rest.get(@reIp[@reSel] + @roomId[@reRoom] + @deviceId[@reRoom][@reDevice] + commandid)
    else
        say "Sorry, I am not programmed for command #{command}."
    end
    request_completed   
  end

QUESTION

How do I define/initialize my hash differently and/or test for a non-match?

  • 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-14T02:17:35+00:00Added an answer on June 14, 2026 at 2:17 am

    You don’t get nil or a String back in case of a failed lookup – instead you get an empty Hash.

    Check if commandid.is_a?(Hash) and commandid.empty? to know if the lookup failed or not.

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

Sidebar

Related Questions

Background I have a CakePHP application that lives in /m/ . I want to
Background have a custom UITableCellView in which I'm using a custom UITextField that I've
Background I have two lists, the first is items which contains around 250 tuples,
Background I have a function that takes a config object as an argument. Within
Background : I have a few different threads which each need to write to
Background: I have a WebPart that makes use of the SPCalendarView control and in
Background I have a dimension table that has a single record for each day.
Let's look at this picture: The left arrow shows that the button background have
Background: I have a design pattern problem that I was hoping someone may be
Background: We have a Webservice that is running under axis2 on a Tomcat. We

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.