Hashieについて少しだけ調べた1

Hashieとは?

Hashを拡張して便利にしてくれる言わずと知れた有名なgemですね。

github.com

使用例

[5] pry(main)> mash = Hashie::Mash.new
=> {}
[6] pry(main)> mash.name?
=> false
[7] pry(main)> mash.name = "Taro"
=> "Taro"
[8] pry(main)> mash.name?
=> true
[9] pry(main)> mash.name
=> "Taro"

Mash以外にも色々実装されている

  • Hashie::Dash
    • A Dash is a 'defined' or 'discrete' Hash...
  • Hashie::Trash
    • A Trash is a 'translated' Dash where the keys can be remapped from a source hash.
  • Hashie::Clash
    • A Clash is a "Chainable Lazy Hash". Inspired by libraries such as Arel
  • Hashie::Rash
    • Rash is a Hash whose keys can be Regexps, or Ranges, which will match many input keys.

なんで調べていたのか?

APIクライアントの依存gemのversion upのためにこの辺いろいろ調べていた次第でした。

自分の周りでよく見る使われ方としてはAPIクライアント内でレスポンスをHashie::Mash.newに渡してアクセスしやすくしているのですが、
3.5.0からは(執筆時点での最新リリースver.は3.5.7)built-in methodを上書きしている場合はlogger出力されるようになっていました。

Add a logging layer to address common issues by michaelherold · Pull Request #381 · intridea/hashie · GitHub

今日はここまで。