APIdock / Ruby
/
Browse About
method

length

v2_5_5 - Show latest stable - Class: Hash
length()
public

Returns the number of key-value pairs in the hash.

h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 }
h.length        #=> 4
h.delete("a")   #=> 200
h.length        #=> 3
VALUE
rb_hash_size(VALUE hash)
{
    return INT2FIX(RHASH_SIZE(hash));
}

Related methods

  • Instance methods
  • <
  • <=
  • ==
  • >
  • >=
  • []
  • []=
  • any?
  • assoc
  • clear
  • compact
  • compact!
  • compare_by_identity
  • compare_by_identity?
  • default
  • default=
  • default_proc
  • default_proc=
  • delete
  • delete_if
  • dig
  • each
  • each_key
  • each_pair
  • each_value
  • empty?
  • eql?
  • fetch
  • fetch_values
  • flatten
  • has_key?
  • has_value?
  • hash
  • include?
  • index
  • initialize_copy
  • inspect
  • invert
  • keep_if
  • key
  • key?
  • keys
  • length
  • member?
  • merge
  • merge!
  • pretty_print
  • pretty_print_cycle
  • rassoc
  • rehash
  • reject
  • reject!
  • replace
  • select
  • select!
  • shift
  • size
  • slice
  • store
  • to_a
  • to_h
  • to_hash
  • to_proc
  • to_s
  • transform_keys
  • transform_keys!
  • transform_values
  • transform_values!
  • update
  • value?
  • values
  • values_at
  • Class methods
  • []
  • new
  • try_convert
APIdock API Documentation Browser

© 2026 APIdock