Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Hash | has_key?

概要

Hash.has_key?

詳細

Hashのキーが存在するか確認する。

サンプル

コード
# encoding: utf-8
require 'tbpgr_utils'

h = {
  hoge: "hoge",
  hige: "hige",
  hage: "hage",
}

bulk_puts_eval binding, <<-EOS
h.has_key? :hoge
h.has_key? :hege
EOS
__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils
出力
h.has_key? :hoge # => true
h.has_key? :hege # => false