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 6964559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:56:25+00:00 2026-05-27T15:56:25+00:00

Why is_a? returns false for a Hash class? Example: value = {x => 3,

  • 0

Why is_a? returns false for a Hash class?

Example:

value = {"x" => 3, "y" => 2}

puts value.class
puts value.is_a?(Hash)

Output:

Hash
false

Im using Ruby 1.9.2

UPDATED: full source of my class:

class LatLng
  include Mongoid::Fields::Serializable

  attr_reader :lat, :lng

  def serialize(value)
    return if value.nil?

    puts value.class
    puts value.is_a?(Hash)

    if value.is_a?(self.class)
      puts "is geopoint" + value.to_json
      {'lng' => value.lng.to_f, 'lat' => value.lat.to_f}
    elsif value.is_a?(Hash)
      hash = value.with_indifferent_access
      puts "is hash" + value.to_json
      {'lng' => hash['lng'].to_f, 'lat' => hash['lat'].to_f}
    end
  end

  def deserialize(value)
    return if value.nil?

    value.is_a?(self.class) ? value : LatLng.new(value['lat'], value['lng'])
  end

  def initialize(lat, lng)
    @lat, @lng = lat.to_f, lng.to_f
  end

  def [](arg)
    case arg
      when "lat"
        @lat
      when "lng"
        @lng
    end
  end

  def to_a
    [lng, lat]
  end

  def ==(other)
    other.is_a?(self.class) && other.lat == lat && other.lng == lng
  end
end
  • 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-05-27T15:56:25+00:00Added an answer on May 27, 2026 at 3:56 pm
    #irb
    ruby-1.9.3-p0 :001 > value = {"x" => 3, "y" => 2}
     => {"x"=>3, "y"=>2} 
    ruby-1.9.3-p0 :002 > value.is_a?(Hash)
     => true
    

    try to disable any gems/extensions you have loaded, and try with clean ruby

    UPDATE:

    try value.is_a?(::Hash)

    PS: try to read about Duck Typing in Ruby. Maybe you should call value.respond_to?(:key) instead of value.is_a?(Hash)

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

Sidebar

Related Questions

Is there a hash function that returns a 16-digit hex value (as MD5 returns
I'm using this code: <script type='text/javascript'> $(document).ready(function () { //Check if url hash value
Using Ruby 1.9.2 Problem Compare the content, not the results, of two procs. I
I am having a problem with hash collisions using short strings in .NET4. EDIT:
How can I create an Object in ruby that will be evaluated to false
There is a command I want to call that returns a string, I want
SqlDataReader.Read() is a method which returns a bool but advanced to the next record
Occasionally I will know that there is a .NET Framework function that returns a
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
The list sort() method is a modifier function that returns None . So if

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.