3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OpenStruct知らなかったので使ってみた

Last updated at Posted at 2015-03-25
hoge = OpenStruct.new
hoge.fuga = 'piyo'
hoge.fuga #=> "piyo"

# 初期値はhashで渡せる
hoge = OpenStruct.new(fuga: 'piyo')
hoge.fuga #=> "piyo"

みたいに簡単に構造体を使うことができる。

※存在しなくてもエラーにならないので、使い方は気をつけないと行けない

hoge = OpenStruct.new
hoge.bar #=> nil

deepに使用するには多少の工夫が必要っぽい
http://andreapavoni.com/blog/2013/4/create-recursive-openstruct-from-a-ruby-hash/#.VRJs6jusUu4

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?