{"id":5758,"date":"2020-08-04T13:32:02","date_gmt":"2020-08-04T04:32:02","guid":{"rendered":"https:\/\/yumishin.com\/?p=5758"},"modified":"2020-08-04T16:45:41","modified_gmt":"2020-08-04T07:45:41","slug":"ruby-super","status":"publish","type":"post","link":"https:\/\/yumishin.com\/?p=5758","title":{"rendered":"\u3010Ruby Gold\u3011Module\u5185\u3068Class\u5185\u306esuper\u306e\u6319\u52d5\u3067\u30cf\u30de\u3063\u305f\u7b87\u6240"},"content":{"rendered":"<p>\u3069\u3046\u3082\u3001\u660e\u65e5RubyGold\u306e\u8a66\u9a13\u3092\u53d7\u3051\u308b\u4e88\u5b9a\u306e\u3082\u306e\u3067\u3059\u3002<\/p>\n<p><span style=\"color: #ff0000;\">\u3055\u3066RubyGold\u306e\u52c9\u5f37\u3057\u3066\u3044\u308b\u6700\u4e2d\u306b\u3001\u30cf\u30de\u3063\u305f\u90e8\u5206\u304cModule\u5185\u3068Class\u5185\u306esuper\u306e\u6319\u52d5\u3067\u3059\u3002<\/span>\u7d50\u5c40module\u5185\u306esuper\u3084class\u5185\u306esuper\u304c\u3069\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8d77\u52d5\u3055\u305b\u308b\u306e\u304b\u304c\u3044\u307e\u3044\u3061\u308f\u304b\u3089\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u304c\u304a\u304d\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u4eca\u56de\u306f\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u7528\u3044\u3066Module\u5185\u3068Class\u5185\u306esuper\u306e\u6319\u52d5\u3092\u307e\u3068\u3081\u3066\u304a\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u7d50\u8ad6\u306f\u300csuper\u306b\u3088\u3063\u3066ancestors\u306e\u9806\u756a\u306b\u540c\u540d\u30e1\u30bd\u30c3\u30c9\u304c\u63a2\u7d22\u3055\u308c\u308b\u300d\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<h2 id=\"i-0\">\u3010Ruby Gold\u3011Module\u5185\u3068Class\u5185\u306esuper\u306e\u6319\u52d5\u3067\u30cf\u30de\u3063\u305f\u7b87\u6240<\/h2>\n<h3 id=\"i-1\">prepend M\u306e\u5834\u5408\u306e\u6319\u52d5<\/h3>\n<p>\u6271\u3046\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002\u4eca\u56de\u306fmodule M\u3092prepend\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>module M\n  def foo\n    super\n    puts \"M#foo\"\n  end\nend\n\nclass C2\n  def foo\n    puts \"C2#foo\"\n  end\nend\n\nclass C &lt; C2\n  def foo\n    super\n    puts \"C#foo\"\n  end\n  prepend M\nend\n\nC.new.foo<\/code><\/pre>\n<\/div>\n<p>\u3061\u306a\u307f\u306b\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068\u3069\u3046\u8868\u793a\u3055\u308c\u308b\u304b\u8003\u3048\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"accordion main_c\"><input type=\"checkbox\" id=\"label84001\" class=\"accordion_input\"><label for=\"label84001\">\u89e3\u7b54\u30fb\u89e3\u8aac<\/label><\/p>\n<div class=\"accordion_content\">\n<p>\u3053\u308c\u3067\u8868\u793a\u3055\u308c\u308b\u9806\u5e8f\u306f<span style=\"color: #ff0000;\">\u300cC2#foo\u3001C#foo\u3001M#foo\u300d<\/span>\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u304c\u8003\u3048\u65b9\u306e\u624b\u9806\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u307e\u305aC.ancestors\u306e\u7d50\u679c\u3092\u78ba\u8a8d\u3057\u3066\u304a\u304d\u307e\u3059\u3002\u3064\u307e\u308a\u5b9f\u884c\u9806\u5e8f\u3067\u3059\u306d\u3002\u3053\u306e\u5834\u5408\u306fprepend M\u306a\u306e\u3067\u300cM, C, C2\u300d\u306e\u9806\u756a\u3067\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u5b9f\u884c\u9806\u5e8f\u3067\u6700\u521d\u306b\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u3063\u3066\u3044\u308bM#foo\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002\u305d\u306e\u4e2d\u306bsuper\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u306d\u3002<span style=\"color: #ff0000;\">\u3053\u3053\u3067\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u304cM#foo\u5185\u306esuper\u3067\u8d77\u52d5\u3059\u308b\u306e\u306fancestors\u3067\u76f4\u5f8c\u306b\u5b9f\u884c\u3055\u308c\u308b\u4e88\u5b9a\u306eC#foo\u3067\u3059\u3002C2#foo\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/span><\/li>\n<li>C#foo\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u304c\u3001\u305d\u306e\u4e2d\u306b\u3082super\u306e\u8a18\u8ff0\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306fancesutors\u306e\u9806\u5e8f\u306e\u76f4\u5f8c\u306b\u3042\u308bC2#foo\u304c\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u7d50\u679c\u3068\u3057\u3066C2\u3067\u306e\u51e6\u7406\u306b\u3088\u3063\u3066\u3001 C2#foo\u304c\u307e\u305a\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u7d9a\u3044\u3066\u51e6\u7406\u304cC\u306b\u623b\u3063\u3066\u3001C#foo\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u6700\u5f8c\u306bM\u306b\u51e6\u7406\u304c\u623b\u3063\u3066\u3001M#foo\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<p>\u30dd\u30a4\u30f3\u30c8\u306fancestors\u306e\u9806\u756a\u3067\u540c\u540d\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3073\u51fa\u3055\u308c\u3066\u3044\u304f\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002super\u3068\u3044\u3046\u3068\u30b9\u30fc\u30d1\u30fc\u30af\u30e9\u30b9\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3076\u3068\u601d\u3044\u304c\u3061\u3067\u3059\u304c\u3001\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3055\u308c\u3066\u3044\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u306e\u304c\u57fa\u672c\u3067\u3059\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3 id=\"i-2\">include M\u306e\u5834\u5408\u306e\u6319\u52d5<\/h3>\n<p>\u5148\u307b\u3069\u3068\u3001\u307b\u3068\u3093\u3069\u540c\u3058\u30b3\u30fc\u30c9\u3067\u3059\u304c\u3001module M\u304cinclude\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>module M\n  def foo\n    super\n    puts \"M#foo\"\n  end\nend\n\nclass C2\n  def foo\n    puts \"C2#foo\"\n  end\nend\n\nclass C &lt; C2\n  def foo\n    super\n    puts \"C#foo\"\n  end\n  include M\nend\n\nC.new.foo<\/code><\/pre>\n<\/div>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3069\u306e\u3088\u3046\u306a\u9806\u756a\u3067\u8868\u793a\u3055\u308c\u308b\u304b\u8003\u3048\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"accordion main_c\"><input type=\"checkbox\" id=\"label77686\" class=\"accordion_input\"><label for=\"label77686\">\u89e3\u7b54\u30fb\u89e3\u8aac<\/label><\/p>\n<div class=\"accordion_content\">\n<p>\u3053\u308c\u3067\u8868\u793a\u3055\u308c\u308b\u9806\u5e8f\u306f<span style=\"color: #ff0000;\">\u300cC2#foo\u3001M#foo\u3001C#foo\u300d<\/span>\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u6319\u52d5\u3092\u7406\u89e3\u3059\u308b\u624b\u9806\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u307e\u305a\u306f\u5b9f\u884c\u9806\u5e8f\u3092\u8003\u3048\u307e\u3059\u3002\u4eca\u5ea6\u306finclude M\u306a\u306e\u3067\u3001C.ancestors\u306e\u7d50\u679c\u306fC, M, C2\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/li>\n<li>C#foo\u30e1\u30bd\u30c3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002\u3053\u3053\u3067\u306e\u30dd\u30a4\u30f3\u30c8\u306fC#foo\u306e\u4e2d\u306b\u8a18\u8ff0\u3055\u308c\u3066\u3044\u308bsuper\u306fC2#foo\u3067\u306f\u306a\u304f\u3001M#foo\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002\u7406\u7531\u306f\u63a2\u7d22\u9806\u5e8f\u306b\u6cbf\u3063\u3066\u30e1\u30bd\u30c3\u30c9\u304c\u63a2\u7d22\u3055\u308c\u308b\u305f\u3081\u3067\u3059\u3002\u3064\u307e\u308aC\u306e\u6b21\u306b\u63a2\u7d22\u3055\u308c\u308b\u306e\u306fM\u3067\u3059\u304b\u3089\u3001super\u306fM\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/li>\n<li>M#foo\u304c\u5b9f\u884c\u3055\u308c\u308b\u3068\u3001super\u304c\u8a18\u8ff0\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u4eca\u5ea6\u306fancestors\u306e\u6700\u5f8c\u306eC2\u306b\u8a18\u8ff0\u3055\u308c\u3066\u3044\u308b\u540c\u540d\u30e1\u30bd\u30c3\u30c9foo\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/li>\n<li>\u7d50\u679c\u3068\u3057\u3066C2#foo\u304c\u307e\u305a\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u7d9a\u3044\u3066\u51e6\u7406\u304cM\u306b\u623b\u3063\u3066M#foo\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u6700\u5f8c\u306bC\u306b\u51e6\u7406\u304c\u623b\u3063\u3066C#foo\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<h4 id=\"i-3\">\u307e\u3068\u3081<\/h4>\n<p><span style=\"color: #ff0000;\">\u4eca\u56de\u306e\u30dd\u30a4\u30f3\u30c8\u306f\u3001super\u306fancestors\u3067\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u9806\u5e8f\u3067\u30e1\u30bd\u30c3\u30c9\u3092\u63a2\u7d22\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/span>\u3060\u304b\u3089class C\u306e\u4e2d\u306bsuper\u304c\u66f8\u3044\u3066\u3042\u3063\u3066\u3082\u3001ancestors\u306e\u9806\u5e8f\u3067M\u304c\u5148\u306a\u3089M\u306e\u540c\u540d\u30e1\u30bd\u30c3\u30c9\u304c\u5148\u306b\u5b9f\u884c\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u306d\u3002<\/p>\n<p>\u304b\u306a\u308a\u30cf\u30de\u3063\u305f\u90e8\u5206\u306a\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3046\u3082\u3001\u660e\u65e5RubyGold\u306e\u8a66\u9a13\u3092\u53d7\u3051\u308b\u4e88\u5b9a\u306e\u3082\u306e\u3067\u3059\u3002 \u3055\u3066RubyGold\u306e\u52c9\u5f37\u3057\u3066\u3044\u308b\u6700\u4e2d\u306b\u3001\u30cf\u30de\u3063\u305f\u90e8\u5206\u304cModule\u5185\u3068Class\u5185\u306esuper\u306e\u6319\u52d5\u3067\u3059\u3002\u7d50\u5c40module\u5185\u306esuper\u3084class\u5185\u306esup &#8230; <\/p>\n","protected":false},"author":1,"featured_media":5759,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[272],"tags":[],"class_list":{"0":"post-5758","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-programing","8":"entry"},"_links":{"self":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5758","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5758"}],"version-history":[{"count":1,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5758\/revisions"}],"predecessor-version":[{"id":5760,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/5758\/revisions\/5760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/media\/5759"}],"wp:attachment":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}