{"image_url":null,"blog_title":"Camera Obscura","width":"100%","title":"define_method \u3068 block_given?\uff08Ruby\uff09","categories":["Ruby"],"description":"Ruby \u3067\u30e1\u30bd\u30c3\u30c9\u306b\u30d6\u30ed\u30c3\u30af\u304c\u4e0e\u3048\u3089\u308c\u3066\u3044\u308b\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3001Kernel#block_given?\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308b\u3002 def foo p block_given? end foo #=>false foo {} #=>true \u3053\u308c\u304c\u3001\u30e1\u30bd\u30c3\u30c9\u3092Module#define_method\u3067\u5b9a\u7fa9\u3057\u305f\u5834\u5408\u3001\u4f7f\u3048\u306a\u3044\u3002 define_method(:foo) do p block_given? end foo #=>false foo {} #=>false \u3068\u3044\u3046\u304b\u3001\u305d\u3082\u305d\u3082\u3053\u306e\u5834\u5408\u3001yield\u304c\u4f7f\u3048\u306a\u3044\u306e\u3067\u3001\u30d6\u30ed\u30c3\u30af\u306f Proc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u4e0e\u3048\u3066\u3084\u308b\u3053\u3068\u306b\u306a\u308b\u3002 define_method(\u2026","blog_url":"https://obelisk.hatenablog.com/","version":"1.0","published":"2025-04-09 13:06:31","provider_name":"Hatena Blog","height":"190","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fobelisk.hatenablog.com%2Fentry%2F2025%2F04%2F09%2F130631\" title=\"define_method \u3068 block_given?\uff08Ruby\uff09 - Camera Obscura\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","author_url":"https://blog.hatena.ne.jp/obelisk2/","author_name":"obelisk2","provider_url":"https://hatena.blog","url":"https://obelisk.hatenablog.com/entry/2025/04/09/130631","type":"rich"}