{"id":133,"date":"2024-09-11T10:08:35","date_gmt":"2024-09-11T01:08:35","guid":{"rendered":"https:\/\/dexall.co.jp\/articles\/?p=133"},"modified":"2025-03-24T08:55:02","modified_gmt":"2025-03-23T23:55:02","slug":"ruby%e5%88%9d%e5%bf%83%e8%80%85%e5%bf%85%e8%a6%8b%ef%bc%81include%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%e8%a1%93%ef%bc%9a%e3%82%b3%e3%83%bc%e3%83%89%e4%be%8b%e3%81%a7","status":"publish","type":"post","link":"https:\/\/dexall.co.jp\/articles\/?p=133","title":{"rendered":"Ruby\u521d\u5fc3\u8005\u5fc5\u898b\uff01include\u306e\u4f7f\u3044\u65b9\u30de\u30b9\u30bf\u30fc\u8853\uff1a\u30b3\u30fc\u30c9\u4f8b\u3067\u5b66\u30765\u3064\u306e\u6d3b\u7528\u30b7\u30fc\u30f3"},"content":{"rendered":"\n<p>Ruby\u306e<code>include<\/code>\u306f\u3001\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u3068\u67d4\u8edf\u6027\u3092\u9ad8\u3081\u308b\u5f37\u529b\u306a\u6a5f\u80fd\u3067\u3059\u3002<br>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<code>include<\/code>\u306e\u57fa\u672c\u304b\u3089\u9ad8\u5ea6\u306a\u4f7f\u7528\u6cd5\u307e\u3067\u3001\u5b9f\u8df5\u7684\u306a\u4f8b\u3092\u4ea4\u3048\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<br>\u521d\u5fc3\u8005\u304b\u3089\u4e2d\u7d1a\u8005\u307e\u3067\u3001Ruby\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u306e\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u306b\u5f79\u7acb\u3064\u60c5\u5831\u304c\u6e80\u8f09\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\">\u3053\u306e\u8a18\u4e8b\u3092\u901a\u3057\u3066\u7406\u89e3\u3067\u304d\u308b7\u3064\u306e\u3053\u3068<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ul class=\"wp-block-list\">\n<li><code>include<\/code>\u306e\u57fa\u672c\u6982\u5ff5\u3068\u4f7f\u7528\u65b9\u6cd5<\/li>\n\n\n\n<li><code>include<\/code>\u3068<code>extend<\/code>\u306e\u9055\u3044\u3068\u9069\u5207\u306a\u4f7f\u3044\u5206\u3051<\/li>\n\n\n\n<li>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u3063\u305f\u52b9\u679c\u7684\u306a\u30b3\u30fc\u30c9\u8a2d\u8a08<\/li>\n\n\n\n<li><code>include<\/code>\u3092\u6d3b\u7528\u3057\u305f\u9ad8\u5ea6\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30c6\u30af\u30cb\u30c3\u30af<\/li>\n\n\n\n<li><code>include<\/code>\u4f7f\u7528\u6642\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff\u3068\u6ce8\u610f\u70b9<\/li>\n\n\n\n<li>\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306b\u304a\u3051\u308b<code>include<\/code>\u306e\u6d3b\u7528\u6cd5<\/li>\n\n\n\n<li><code>include<\/code>\u30de\u30b9\u30bf\u30fc\u306b\u306a\u308b\u305f\u3081\u306e\u5b66\u7fd2\u30d1\u30b9\u3068\u30ea\u30bd\u30fc\u30b9<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>116<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>121<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>128<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\" data-dialog-title=\"\u76ee\u6b21\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">1. Ruby\u306einclude\u3068\u306f\uff1f\u57fa\u672c\u6982\u5ff5\u3092\u62bc\u3055\u3048\u3088\u3046<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">\u30e2\u30b8\u30e5\u30fc\u30eb\u3068include\u306e\u95a2\u4fc2\u6027<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-2\">include\u304c\u3082\u305f\u3089\u30593\u3064\u306e\u30e1\u30ea\u30c3\u30c8<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-6\">2. include\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\uff1a\u5177\u4f53\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3067\u89e3\u8aac<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-7\">\u30b7\u30f3\u30d7\u30eb\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u4f5c\u6210\u3068\u4f7f\u7528\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-8\">\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u540c\u6642\u306b\u4f7f\u7528\u3059\u308b\u6280\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-9\">\u5b9f\u8df5\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\uff1a\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u95a2\u6570\u306e\u5171\u6709<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-10\">\u307e\u3068\u3081<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-11\">3. include\u3068extend\u306e\u9055\u3044\u3092\u5fb9\u5e95\u6bd4\u8f03<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-12\">\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9 vs \u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9\uff1a\u4f7f\u3044\u5206\u3051\u306e\u30dd\u30a4\u30f3\u30c8<\/a>      <\/li>      <li>        <a href=\"#i-13\">\u5b9f\u8df5\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3067\u898b\u308binclude\u3068extend\u306e\u4f7f\u3044\u6240<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-14\">\u307e\u3068\u3081<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-15\">4. \u9a5a\u304d\u306e\u6d3b\u7528\u6cd5\uff1ainclude\u3067\u5b9f\u73fe\u3059\u308b5\u3064\u306e\u30c6\u30af\u30cb\u30c3\u30af<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-16\">1. \u540d\u524d\u7a7a\u9593\u306e\u7ba1\u7406\uff1a\u30b3\u30fc\u30c9\u306e\u6574\u7406\u6574\u9813\u8853<\/a>      <\/li>      <li>        <a href=\"#i-17\">2. \u632f\u308b\u821e\u3044\u306e\u8ffd\u52a0\uff1a\u65e2\u5b58\u30af\u30e9\u30b9\u306e\u6a5f\u80fd\u62e1\u5f35<\/a>      <\/li>      <li>        <a href=\"#i-18\">3. \u30df\u30c3\u30af\u30b9\u30a4\u30f3\uff1a\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u9b54\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-19\">4. \u30d5\u30c3\u30af\u30e1\u30bd\u30c3\u30c9\u306e\u6d3b\u7528\uff1aincluded, extended, prepended<\/a>      <\/li>      <li>        <a href=\"#i-20\">5. \u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\uff1a\u52d5\u7684\u306b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u751f\u6210\u3057\u3066\u4f7f\u7528\u3059\u308b<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-21\">\u307e\u3068\u3081<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-22\">5. include\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3068\u6ce8\u610f\u70b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-23\">\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u3068\u5b9f\u884c\u901f\u5ea6\u3078\u306e\u5f71\u97ff<\/a>      <\/li>      <li>        <a href=\"#i-24\">\u6ce8\u610f\u70b9\u3068\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>      <\/li>      <li>        <a href=\"#i-28\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316\u306e\u30d2\u30f3\u30c8<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-29\">\u307e\u3068\u3081<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-30\">6. \u5b9f\u8df5\u6f14\u7fd2\uff1ainclude\u3092\u4f7f\u3063\u305f\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u4f8b<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-31\">Before\uff1a\u30b9\u30d1\u30b2\u30c3\u30c6\u30a3\u30b3\u30fc\u30c9\u306e\u554f\u984c\u70b9<\/a>      <\/li>      <li>        <a href=\"#i-32\">\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306e\u30d7\u30ed\u30bb\u30b9<\/a>      <\/li>      <li>        <a href=\"#i-33\">After\uff1ainclude\u3092\u4f7f\u3063\u3066\u7f8e\u3057\u304f\u6574\u7406\u3055\u308c\u305f\u30b3\u30fc\u30c9<\/a>      <\/li>      <li>        <a href=\"#i-34\">\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306b\u3088\u308b\u6539\u5584\u70b9<\/a>      <\/li>      <li>        <a href=\"#i-35\">\u5b9f\u8df5\u7684\u306a\u30b7\u30ca\u30ea\u30aa<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-36\">\u307e\u3068\u3081<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-37\">7. \u307e\u3068\u3081\uff1ainclude\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-38\">include\u306e\u4f7f\u3044\u3053\u306a\u3057\u3067\u5f97\u3089\u308c\u308b3\u3064\u306e\u6210\u679c<\/a>      <\/li>      <li>        <a href=\"#i-42\">\u3055\u3089\u306a\u308b\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3068\u6b21\u306e\u30b9\u30c6\u30c3\u30d7<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-46\">\u6700\u5f8c\u306b<\/a>      <\/li>    <\/ul>  <\/li><\/ul>\n      <a href=\"#\" class=\"sgb-toc-button js-toc-button\" rel=\"nofollow\" data-open-dialog=\"true\"><i class=\"fa fa-list\"><\/i><span class=\"sgb-toc-button__text\">\u76ee\u6b21\u3078<\/span><\/a>\n    <\/div><\/div><h2 class=\"wp-block-sgb-headings sgb-heading\" id=\"i-0\"><span class=\"sgb-heading__inner sgb-heading--type1 with-icon\" style=\"background-color:transparent;border-color:transparent;font-size:1.2em\"><i class=\"fa fa-check\" style=\"color:var(--wp--preset--color--sango-main)\"><\/i><span class=\"sgb-heading__text\" style=\"color:#333\">1. Ruby\u306einclude\u3068\u306f\uff1f\u57fa\u672c\u6982\u5ff5\u3092\u62bc\u3055\u3048\u3088\u3046<\/span><\/span><\/h2>\n\n\n\n<p>Ruby\u3067\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u59cb\u3081\u305f\u3070\u304b\u308a\u306e\u65b9\u3084\u3001\u30b3\u30fc\u30c9\u306e\u6574\u7406\u306b\u60a9\u3093\u3067\u3044\u308b\u958b\u767a\u8005\u306e\u7686\u3055\u3093\u3001<code>include<\/code>\u3068\u3044\u3046\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u3088\u304f\u76ee\u306b\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u304b\uff1f<br>\u4eca\u56de\u306f\u3001\u3053\u306eRuby\u306e\u5f37\u529b\u306a\u6a5f\u80fd\u306b\u3064\u3044\u3066\u3001\u57fa\u672c\u304b\u3089\u5fb9\u5e95\u7684\u306b\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">\u30e2\u30b8\u30e5\u30fc\u30eb\u3068include\u306e\u95a2\u4fc2\u6027<\/h3>\n\n\n\n<p>\u307e\u305a\u3001<code>include<\/code>\u3092\u7406\u89e3\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3044\u3046\u6982\u5ff5\u3092\u62bc\u3055\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n<div id=\"id-32e133f2-1e3c-484e-862b-ff3155d0ecd4\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u30e2\u30b8\u30e5\u30fc\u30eb<\/th><th>include<\/th><\/tr><\/thead><tbody><tr><td>\u95a2\u9023\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3084\u30af\u30e9\u30b9\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f<\/td><td>\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u5b9a\u7fa9\u3055\u308c\u305f\u30e1\u30bd\u30c3\u30c9\u3092\u30af\u30e9\u30b9\u3084\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u624b\u6bb5<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<p>\u30e2\u30b8\u30e5\u30fc\u30eb\u306f\u3001\u3044\u308f\u3070\u300c\u6a5f\u80fd\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u300d\u3067\u3059\u3002<br>\u4e00\u65b9\u3001<code>include<\/code>\u306f\u3001\u305d\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30af\u30e9\u30b9\u306b\u53d6\u308a\u8fbc\u3080\u305f\u3081\u306e\u300c\u958b\u5c01\u30c4\u30fc\u30eb\u300d\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u30af\u30e9\u30b9\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module Greeting\n  def say_hello\n    puts \"Hello, World!\"\n  end\nend\n\nclass Person\n  include Greeting\nend\n\nperson = Person.new\nperson.say_hello  # \u51fa\u529b: Hello, World!<\/pre>\n\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001<code>Greeting<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u5b9a\u7fa9\u3055\u308c\u305f<code>say_hello<\/code>\u30e1\u30bd\u30c3\u30c9\u304c\u3001<code>include<\/code>\u3092\u4f7f\u3063\u3066<code>Person<\/code>\u30af\u30e9\u30b9\u306b\u8ffd\u52a0\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">include\u304c\u3082\u305f\u3089\u30593\u3064\u306e\u30e1\u30ea\u30c3\u30c8<\/h3>\n\n\n\n<p><code>include<\/code>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u4ee5\u4e0b\u306e3\u3064\u306e\u5927\u304d\u306a\u30e1\u30ea\u30c3\u30c8\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-3\">1. <strong>\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u5411\u4e0a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u540c\u3058\u6a5f\u80fd\u3092\u8907\u6570\u306e\u30af\u30e9\u30b9\u3067\u4f7f\u3044\u56de\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n\n\n\n<li>DRY\uff08Don\u2019t Repeat Yourself\uff09\u306e\u539f\u5247\u306b\u5f93\u3063\u305f\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-4\">2. <strong>\u6a5f\u80fd\u306e\u6c34\u5e73\u7684\u306a\u62e1\u5f35<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30af\u30e9\u30b9\u306e\u7d99\u627f\u3092\u4f7f\u308f\u305a\u306b\u3001\u5fc5\u8981\u306a\u6a5f\u80fd\u3060\u3051\u3092\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u67d4\u8edf\u306a\u6a5f\u80fd\u62e1\u5f35\u304c\u53ef\u80fd\u3067\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-5\">3. <strong>\u540d\u524d\u7a7a\u9593\u306e\u7ba1\u7406<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u95a2\u9023\u3059\u308b\u6a5f\u80fd\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306b\u307e\u3068\u3081\u308b\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u306e\u6574\u7406\u6574\u9813\u304c\u3057\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u540d\u524d\u306e\u885d\u7a81\u3092\u907f\u3051\u3084\u3059\u304f\u306a\u308a\u3001\u5927\u898f\u6a21\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3082\u7ba1\u7406\u304c\u3057\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30e1\u30ea\u30c3\u30c8\u3092\u6d3b\u304b\u3059\u3053\u3068\u3067\u3001\u3088\u308a\u67d4\u8edf\u3067\u4fdd\u5b88\u6027\u306e\u9ad8\u3044Ruby\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>include<\/code>\u306e\u5177\u4f53\u7684\u306a\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u3001\u30b3\u30fc\u30c9\u4f8b\u3092\u4ea4\u3048\u3066\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\" id=\"i-6\"><span class=\"sgb-heading__inner sgb-heading--type1 with-icon\" style=\"background-color:transparent;border-color:transparent;font-size:1.2em\"><i class=\"fa fa-check\" style=\"color:var(--wp--preset--color--sango-main)\"><\/i><span class=\"sgb-heading__text\" style=\"color:#333\">2. include\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\uff1a\u5177\u4f53\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3067\u89e3\u8aac<\/span><\/span><\/h2>\n\n\n\n<p><code>include<\/code>\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u306f\u3001Ruby\u3067\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u6d3b\u7528\u306e\u7b2c\u4e00\u6b69\u3067\u3059\u3002<br>\u3053\u3053\u3067\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u4f5c\u6210\u304b\u3089\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u540c\u6642\u4f7f\u7528\u307e\u3067\u3001\u5177\u4f53\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3092\u4ea4\u3048\u3066\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-7\">\u30b7\u30f3\u30d7\u30eb\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u4f5c\u6210\u3068\u4f7f\u7528\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u307e\u305a\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u3001\u305d\u308c\u3092\u30af\u30e9\u30b9\u3067\u4f7f\u7528\u3059\u308b\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u65e5\u4ed8\u64cd\u4f5c\u7528\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\nmodule DateHelper\n  def format_date(date)\n    date.strftime(\"%Y-%m-%d\")\n  end\n\n  def days_ago(days)\n    (Date.today - days).strftime(\"%Y-%m-%d\")\n  end\nend\n\n# DateHelper\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3059\u308b\u30af\u30e9\u30b9\nclass Event\n  include DateHelper\n\n  def initialize(name, date)\n    @name = name\n    @date = date\n  end\n\n  def display_info\n    puts \"\u30a4\u30d9\u30f3\u30c8: #{@name}\"\n    puts \"\u958b\u50ac\u65e5: #{format_date(@date)}\"\n    puts \"1\u9031\u9593\u524d: #{days_ago(7)}\"\n  end\nend\n\n# \u4f7f\u7528\u4f8b\nevent = Event.new(\"Ruby\u52c9\u5f37\u4f1a\", Date.new(2024, 9, 15))\nevent.display_info<\/pre>\n\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u4f8b\u3067\u306f\u3001<code>DateHelper<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u65e5\u4ed8\u64cd\u4f5c\u7528\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3057\u3001<code>Event<\/code>\u30af\u30e9\u30b9\u3067\u305d\u308c\u3092<code>include<\/code>\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001<code>Event<\/code>\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066<code>format_date<\/code>\u3068<code>days_ago<\/code>\u304c\u4f7f\u7528\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-8\">\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u540c\u6642\u306b\u4f7f\u7528\u3059\u308b\u6280\u6cd5<\/h3>\n\n\n\n<p>Ruby\u3067\u306f\u30011\u3064\u306e\u30af\u30e9\u30b9\u306b\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092<code>include<\/code>\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001\u7570\u306a\u308b\u6a5f\u80fd\u3092\u6301\u3064\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u3001\u67d4\u8edf\u306b\u30af\u30e9\u30b9\u306e\u6a5f\u80fd\u3092\u62e1\u5f35\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module Loggable\n  def log(message)\n    puts \"[LOG] #{Time.now}: #{message}\"\n  end\nend\n\nmodule Validatable\n  def validate_presence(value, field_name)\n    raise ArgumentError, \"#{field_name} cannot be empty\" if value.nil? || value.empty?\n  end\nend\n\nclass User\n  include Loggable\n  include Validatable\n\n  def initialize(name, email)\n    validate_presence(name, \"Name\")\n    validate_presence(email, \"Email\")\n    @name = name\n    @email = email\n    log(\"New user created: #{name}\")\n  end\nend\n# \u4f7f\u7528\u4f8b\nbegin\n  user = User.new(\"Alice\", \"alice@example.com\")\n  user = User.new(\"\", \"bob@example.com\")  # \u3053\u308c\u306f\u30a8\u30e9\u30fc\u3092\u767a\u751f\u3055\u305b\u307e\u3059\nrescue ArgumentError =&gt; e\n  puts \"\u30a8\u30e9\u30fc: #{e.message}\"\nend<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>Loggable<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u30ed\u30b0\u6a5f\u80fd\u3092\u3001<code>Validatable<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002<br><code>User<\/code>\u30af\u30e9\u30b9\u306f\u4e21\u65b9\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092<code>include<\/code>\u3059\u308b\u3053\u3068\u3067\u3001\u3053\u308c\u3089\u306e\u6a5f\u80fd\u3092\u540c\u6642\u306b\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-9\">\u5b9f\u8df5\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\uff1a\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u95a2\u6570\u306e\u5171\u6709<\/h3>\n\n\n\n<p><code>include<\/code>\u306e\u5f37\u529b\u306a\u4f7f\u7528\u4f8b\u3068\u3057\u3066\u3001\u8907\u6570\u306e\u30af\u30e9\u30b9\u3067\u5171\u901a\u3057\u3066\u4f7f\u7528\u3059\u308b\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u95a2\u6570\u3092\u5171\u6709\u3059\u308b\u65b9\u6cd5\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module StringUtility\n  def truncate(string, length = 30)\n    return string unless string.length &gt; length\n    string[0...length] + \"...\"\n  end\n\n  def capitalize_words(string)\n    string.split.map(&amp;:capitalize).join(' ')\n  end\nend\n\nclass BlogPost\n  include StringUtility\n\n  def initialize(title, content)\n    @title = capitalize_words(title)\n    @content = content\n  end\n\n  def summary\n    truncate(@content)\n  end\nend\n\nclass Comment\n  include StringUtility\n\n  def initialize(author, text)\n    @author = capitalize_words(author)\n    @text = text\n  end\n\n  def display\n    \"#{@author}: #{truncate(@text, 20)}\"\n  end\nend\n\n# \u4f7f\u7528\u4f8b\npost = BlogPost.new(\"ruby programming tips\", \"Ruby\u306f\u7d20\u6674\u3089\u3057\u3044\u8a00\u8a9e\u3067\u3059\u3002\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u6982\u5ff5\u3092...\")\nputs post.summary\n\ncomment = Comment.new(\"john doe\", \"\u3053\u306e\u8a18\u4e8b\u306f\u3068\u3066\u3082\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\uff01\")\nputs comment.display<\/pre>\n\n\n\n<p>\u3053\u306e\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3067\u306f\u3001<code>StringUtility<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3057\u3001<code>BlogPost<\/code>\u30af\u30e9\u30b9\u3068<code>Comment<\/code>\u30af\u30e9\u30b9\u306e\u4e21\u65b9\u3067\u305d\u308c\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3092\u907f\u3051\u3001\u6a5f\u80fd\u306e\u4e00\u8cab\u6027\u3092\u4fdd\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-10\">\u307e\u3068\u3081<\/h3>\n\n\n\n<p><code>include<\/code>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5229\u70b9\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\"><code>include<\/code>\u3092\u5229\u7528\u3059\u308b3\u3064\u306e\u5229\u70b9<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ol class=\"wp-block-list\">\n<li>\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u304c\u9ad8\u307e\u308b<\/li>\n\n\n\n<li>\u95a2\u9023\u3059\u308b\u6a5f\u80fd\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u307e\u3068\u3081\u308b\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u306e\u6574\u7406\u304c\u3057\u3084\u3059\u304f\u306a\u308b<\/li>\n\n\n\n<li>\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u67d4\u8edf\u306a\u6a5f\u80fd\u62e1\u5f35\u304c\u53ef\u80fd\u306b\u306a\u308b<\/li>\n<\/ol>\n<\/div><\/div>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u4f8b\u3092\u53c2\u8003\u306b\u3001\u81ea\u5206\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3082<code>include<\/code>\u3092\u6d3b\u7528\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4e0a\u624b\u306b\u4f7f\u3044\u3053\u306a\u3059\u3053\u3068\u3067\u3001\u3088\u308a\u6574\u7406\u3055\u308c\u305f\u3001\u4fdd\u5b88\u6027\u306e\u9ad8\u3044Ruby\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>include<\/code>\u3068<code>extend<\/code>\u306e\u9055\u3044\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<br>\u3053\u308c\u3089\u306e\u4f7f\u3044\u5206\u3051\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u3001\u3055\u3089\u306b\u52b9\u679c\u7684\u306b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u6d3b\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\" id=\"i-11\"><span class=\"sgb-heading__inner sgb-heading--type1 with-icon\" style=\"background-color:transparent;border-color:transparent;font-size:1.2em\"><i class=\"fa fa-check\" style=\"color:var(--wp--preset--color--sango-main)\"><\/i><span class=\"sgb-heading__text\" style=\"color:#333\">3. include\u3068extend\u306e\u9055\u3044\u3092\u5fb9\u5e95\u6bd4\u8f03<\/span><\/span><\/h2>\n\n\n\n<p>Ruby\u3067\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3059\u308b\u969b\u3001<code>include<\/code>\u3068<code>extend<\/code>\u3068\u3044\u30462\u3064\u306e\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u3088\u304f\u76ee\u306b\u3057\u307e\u3059\u3002<br>\u3053\u308c\u3089\u306f\u4f3c\u3066\u3044\u308b\u3088\u3046\u3067\u7570\u306a\u308b\u52d5\u4f5c\u3092\u3059\u308b\u305f\u3081\u3001\u9069\u5207\u306b\u4f7f\u3044\u5206\u3051\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<br>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>include<\/code>\u3068<code>extend<\/code>\u306e\u9055\u3044\u3092\u8a73\u3057\u304f\u89e3\u8aac\u3057\u3001\u305d\u308c\u305e\u308c\u306e\u9069\u5207\u306a\u4f7f\u7528\u5834\u9762\u3092\u63a2\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-12\">\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9 vs \u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9\uff1a\u4f7f\u3044\u5206\u3051\u306e\u30dd\u30a4\u30f3\u30c8<\/h3>\n\n\n\n<p><code>include<\/code>\u3068<code>extend<\/code>\u306e\u4e3b\u306a\u9055\u3044\u306f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u3069\u306e\u3088\u3046\u306b\u8ffd\u52a0\u3059\u308b\u304b\u306b\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n<div id=\"id-c19439ce-e883-4e32-accc-d951b887b54d\">\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u30ad\u30fc\u30ef\u30fc\u30c9<\/th><th>\u8ffd\u52a0\u3055\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u306e\u7a2e\u985e<\/th><th>\u547c\u3073\u51fa\u3057\u65b9<\/th><\/tr><\/thead><tbody><tr><td>include<\/td><td>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9<\/td><td>\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5bfe\u3057\u3066\u547c\u3073\u51fa\u3059<\/td><\/tr><tr><td>extend<\/td><td>\u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9<\/td><td>\u30af\u30e9\u30b9\u81ea\u4f53\u306b\u5bfe\u3057\u3066\u547c\u3073\u51fa\u3059<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n<p>\u305d\u308c\u3067\u306f\u3001\u5177\u4f53\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3067\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module Greetable\n  def greet\n    puts \"Hello, I'm #{name}!\"\n  end\nend\n\nclass Person\n  include Greetable\n\n  def initialize(name)\n    @name = name\n  end\n\n  def name\n    @name\n  end\nend\n\nperson = Person.new(\"Alice\")\nperson.greet  # \u51fa\u529b: Hello, I'm Alice!\n\n# extend\u306e\u4f8b\nmodule Countable\n  def count_instances\n    @count ||= 0\n    @count += 1\n  end\nend\n\nclass Car\n  extend Countable\n\n  def initialize(model)\n    @model = model\n    self.class.count_instances\n  end\nend\n\nCar.new(\"Toyota\")\nCar.new(\"Honda\")\nputs Car.count_instances  # \u51fa\u529b: 2<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>Greetable<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u306f<code>include<\/code>\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001<code>Person<\/code>\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066<code>greet<\/code>\u304c\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<br>\u4e00\u65b9\u3001<code>Countable<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u306f<code>extend<\/code>\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001<code>Car<\/code>\u30af\u30e9\u30b9\u81ea\u4f53\u306e\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066<code>count_instances<\/code>\u304c\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-13\">\u5b9f\u8df5\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3067\u898b\u308binclude\u3068extend\u306e\u4f7f\u3044\u6240<\/h3>\n\n\n\n<p>\u3088\u308a\u5b9f\u8df5\u7684\u306a\u4f8b\u3067\u3001<code>include<\/code>\u3068<code>extend<\/code>\u306e\u9069\u5207\u306a\u4f7f\u7528\u5834\u9762\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module Loggable\n  def log(message)\n    puts \"[#{Time.now}] #{message}\"\n  end\nend\n\nmodule Validatable\n  def validate_presence(value, field_name)\n    raise ArgumentError, \"#{field_name} cannot be empty\" if value.to_s.strip.empty?\n  end\nend\n\nclass User\n  include Loggable\n  extend Validatable\n\n  def initialize(name, email)\n    self.class.validate_presence(name, \"Name\")\n    self.class.validate_presence(email, \"Email\")\n    @name = name\n    @email = email\n    log(\"New user created: #{name}\")\n  end\n\n  def self.create(name, email)\n    validate_presence(name, \"Name\")\n    validate_presence(email, \"Email\")\n    new(name, email)\n  end\nend\n\n# \u4f7f\u7528\u4f8b\nuser = User.new(\"Alice\", \"alice@example.com\")\nUser.create(\"Bob\", \"bob@example.com\")\nUser.create(\"\", \"\")  # ArgumentError\u304c\u767a\u751f\u3057\u307e\u3059<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>Loggable<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092<code>include<\/code>\u3059\u308b\u3053\u3068\u3067\u3001\u5404<code>User<\/code>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u30ed\u30b0\u3092\u8a18\u9332\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br>\u4e00\u65b9\u3001<code>Validatable<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092<code>extend<\/code>\u3059\u308b\u3053\u3068\u3067\u3001<code>User<\/code>\u30af\u30e9\u30b9\u81ea\u4f53\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u3092\u6301\u3061\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210\u524d\u306b\u30c7\u30fc\u30bf\u306e\u691c\u8a3c\u3092\u884c\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-14\">\u307e\u3068\u3081<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>include<\/code>\u306f\u4e3b\u306b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u56fa\u6709\u306e\u632f\u308b\u821e\u3044\u3092\u8ffd\u52a0\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>extend<\/code>\u306f\u30af\u30e9\u30b9\u5168\u4f53\u306b\u95a2\u308f\u308b\u6a5f\u80fd\u3084\u3001\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u305f\u3044\u5834\u5408\u306b\u9069\u3057\u3066\u3044\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u4e21\u8005\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u67d4\u8edf\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u8a2d\u8a08\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u9069\u5207\u306b<code>include<\/code>\u3068<code>extend<\/code>\u3092\u4f7f\u3044\u5206\u3051\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u8868\u73fe\u529b\u8c4a\u304b\u3067\u4fdd\u5b88\u6027\u306e\u9ad8\u3044Ruby\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u57fa\u672c\u3092\u8e0f\u307e\u3048\u305f\u4e0a\u3067\u3001\u3055\u3089\u306b\u9ad8\u5ea6\u306a<code>include<\/code>\u306e\u6d3b\u7528\u6cd5\u306b\u3064\u3044\u3066\u63a2\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\" id=\"i-15\"><span class=\"sgb-heading__inner sgb-heading--type1 with-icon\" style=\"background-color:transparent;border-color:transparent;font-size:1.2em\"><i class=\"fa fa-check\" style=\"color:var(--wp--preset--color--sango-main)\"><\/i><span class=\"sgb-heading__text\" style=\"color:#333\">4. \u9a5a\u304d\u306e\u6d3b\u7528\u6cd5\uff1ainclude\u3067\u5b9f\u73fe\u3059\u308b5\u3064\u306e\u30c6\u30af\u30cb\u30c3\u30af<\/span><\/span><\/h2>\n\n\n\n<p><code>include<\/code>\u306f\u5358\u306b\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u30af\u30e9\u30b9\u306b\u8ffd\u52a0\u3059\u308b\u3060\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<br>\u9069\u5207\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u306e\u6574\u7406\u3001\u6a5f\u80fd\u306e\u62e1\u5f35\u3001\u305d\u3057\u3066\u9ad8\u5ea6\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30c6\u30af\u30cb\u30c3\u30af\u306e\u5b9f\u73fe\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<br>\u3053\u3053\u3067\u306f\u3001<code>include<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u73fe\u3067\u304d\u308b5\u3064\u306e\u9a5a\u304d\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-16\">1. \u540d\u524d\u7a7a\u9593\u306e\u7ba1\u7406\uff1a\u30b3\u30fc\u30c9\u306e\u6574\u7406\u6574\u9813\u8853<\/h3>\n\n\n\n<p>\u540d\u524d\u7a7a\u9593\u306e\u7ba1\u7406\u306f\u3001\u5927\u898f\u6a21\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u30b3\u30fc\u30c9\u3092\u6574\u7406\u3059\u308b\u4e0a\u3067\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002<br>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u95a2\u9023\u3059\u308b\u5b9a\u6570\u3084\u30af\u30e9\u30b9\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u3001\u540d\u524d\u306e\u885d\u7a81\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module MyApp\n  module Utils\n    class StringFormatter\n      def self.capitalize_words(string)\n        string.split.map(&amp;:capitalize).join(' ')\n      end\n    end\n  end\n\n  class User\n    def full_name\n      first_name = \"john\"\n      last_name = \"doe\"\n      Utils::StringFormatter.capitalize_words(\"#{first_name} #{last_name}\")\n    end\n  end\nend\n\nuser = MyApp::User.new\nputs user.full_name  # \u51fa\u529b: John Doe<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>MyApp<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306b<code>Utils<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3068<code>User<\/code>\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001\u4ed6\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3084\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u306e\u540d\u524d\u885d\u7a81\u3092\u907f\u3051\u3064\u3064\u3001\u95a2\u9023\u3059\u308b\u6a5f\u80fd\u3092\u307e\u3068\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-17\">2. \u632f\u308b\u821e\u3044\u306e\u8ffd\u52a0\uff1a\u65e2\u5b58\u30af\u30e9\u30b9\u306e\u6a5f\u80fd\u62e1\u5f35<\/h3>\n\n\n\n<p><code>include<\/code>\u3092\u4f7f\u7528\u3057\u3066\u3001\u65e2\u5b58\u306e\u30af\u30e9\u30b9\u306b\u65b0\u3057\u3044\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u3053\u308c\u306f\u7279\u306b\u3001\u30b3\u30a2\u30af\u30e9\u30b9\u306e\u62e1\u5f35\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module StringExtensions\n  def palindrome?\n    cleaned = self.downcase.gsub(\/[^a-z0-9]\/, '')\n    cleaned == cleaned.reverse\n  end\nend\n\nclass String\n  include StringExtensions\nend\n\nputs \"A man, a plan, a canal: Panama\".palindrome?  # \u51fa\u529b: true\nputs \"Hello, World!\".palindrome?  # \u51fa\u529b: false<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>String<\/code>\u30af\u30e9\u30b9\u306b<code>palindrome?<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u3092\u4f7f\u7528\u3059\u308b\u969b\u306f\u3001\u65e2\u5b58\u306e\u30e1\u30bd\u30c3\u30c9\u540d\u3068\u306e\u885d\u7a81\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-18\">3. \u30df\u30c3\u30af\u30b9\u30a4\u30f3\uff1a\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u9b54\u6cd5<\/h3>\n\n\n\n<p>\u30df\u30c3\u30af\u30b9\u30a4\u30f3\u306f\u3001\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u67d4\u8edf\u306b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b\u5f37\u529b\u306a\u30c6\u30af\u30cb\u30c3\u30af\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module Swimmable\n  def swim\n    \"I'm swimming!\"\n  end\nend\n\nmodule Flyable\n  def fly\n    \"I'm flying!\"\n  end\nend\n\nclass Duck\n  include Swimmable\n  include Flyable\nend\n\nduck = Duck.new\nputs duck.swim  # \u51fa\u529b: I'm swimming!\nputs duck.fly   # \u51fa\u529b: I'm flying!<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>Duck<\/code>\u30af\u30e9\u30b9\u304c<code>Swimmable<\/code>\u3068<code>Flyable<\/code>\u4e21\u65b9\u306e\u6a5f\u80fd\u3092\u6301\u3064\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001\u5358\u4e00\u7d99\u627f\u306e\u5236\u9650\u3092\u8d85\u3048\u3066\u3001\u67d4\u8edf\u306a\u30af\u30e9\u30b9\u8a2d\u8a08\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-19\">4. \u30d5\u30c3\u30af\u30e1\u30bd\u30c3\u30c9\u306e\u6d3b\u7528\uff1aincluded, extended, prepended<\/h3>\n\n\n\n<p>Ruby\u306f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u53d6\u308a\u8fbc\u307e\u308c\u308b\u969b\u306b\u81ea\u52d5\u7684\u306b\u5b9f\u884c\u3055\u308c\u308b\u30d5\u30c3\u30af\u30e1\u30bd\u30c3\u30c9\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u308c\u3089\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u53d6\u308a\u8fbc\u307f\u6642\u306b\u8ffd\u52a0\u306e\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module Loggable\n  def self.included(base)\n    base.extend(ClassMethods)\n  end\n\n  def log(message)\n    puts \"[#{Time.now}] #{message}\"\n  end\n\n  module ClassMethods\n    def class_log(message)\n      puts \"[CLASS #{Time.now}] #{message}\"\n    end\n  end\nend\n\nclass MyClass\n  include Loggable\nend\n\nMyClass.class_log(\"Class method called\")  # \u51fa\u529b: [CLASS 2024-09-11 12:00:00] Class method called\nMyClass.new.log(\"Instance method called\") # \u51fa\u529b: [2024-09-11 12:00:00] Instance method called<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>included<\/code>\u30d5\u30c3\u30af\u3092\u4f7f\u7528\u3057\u3066\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u53d6\u308a\u8fbc\u307e\u308c\u305f\u969b\u306b\u81ea\u52d5\u7684\u306b\u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9\u3082\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-20\">5. \u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\uff1a\u52d5\u7684\u306b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u751f\u6210\u3057\u3066\u4f7f\u7528\u3059\u308b<\/h3>\n\n\n\n<p>\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u5b9f\u884c\u6642\u306b\u52d5\u7684\u306b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u751f\u6210\u3057\u3001\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001\u975e\u5e38\u306b\u67d4\u8edf\u306a\u30b3\u30fc\u30c9\u8a2d\u8a08\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def create_logger(name)\n  Module.new do\n    define_method(\"log_#{name}\") do |message|\n      puts \"[#{name.upcase}] #{message}\"\n    end\n  end\nend\n\nclass MyApp\n  include create_logger(\"info\")\n  include create_logger(\"error\")\nend\n\napp = MyApp.new\napp.log_info(\"Application started\")  # \u51fa\u529b: [INFO] Application started\napp.log_error(\"An error occurred\")   # \u51fa\u529b: [ERROR] An error occurred<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>create_logger<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u52d5\u7684\u306b\u30ed\u30ac\u30fc\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001\u7570\u306a\u308b\u30ed\u30b0\u30ec\u30d9\u30eb\u306b\u5bfe\u5fdc\u3057\u305f\u30e1\u30bd\u30c3\u30c9\u3092\u67d4\u8edf\u306b\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-21\">\u307e\u3068\u3081<\/h3>\n\n\n\n<p>\u3053\u308c\u3089\u306e5\u3064\u306e\u30c6\u30af\u30cb\u30c3\u30af\u306f\u3001<code>include<\/code>\u306e\u53ef\u80fd\u6027\u3092\u5927\u304d\u304f\u5e83\u3052\u307e\u3059\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u540d\u524d\u7a7a\u9593\u306e\u7ba1\u7406\u3067\u30b3\u30fc\u30c9\u3092\u6574\u7406\u3059\u308b<\/li>\n\n\n\n<li>\u65e2\u5b58\u30af\u30e9\u30b9\u306b\u65b0\u3057\u3044\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b<\/li>\n\n\n\n<li>\u30df\u30c3\u30af\u30b9\u30a4\u30f3\u3067\u8907\u6570\u306e\u6a5f\u80fd\u3092\u7d44\u307f\u5408\u308f\u305b\u308b<\/li>\n\n\n\n<li>\u30d5\u30c3\u30af\u30e1\u30bd\u30c3\u30c9\u3067\u30e2\u30b8\u30e5\u30fc\u30eb\u53d6\u308a\u8fbc\u307f\u6642\u306e\u6319\u52d5\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b<\/li>\n\n\n\n<li>\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u52d5\u7684\u306b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u751f\u6210\u3059\u308b<\/li>\n<\/ol>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u9069\u5207\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u67d4\u8edf\u3067\u4fdd\u5b88\u6027\u306e\u9ad8\u3044Ruby\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u305f\u3060\u3057\u3001\u7279\u306b\u65e2\u5b58\u30af\u30e9\u30b9\u306e\u62e1\u5f35\u3084\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u4f7f\u7528\u3059\u308b\u969b\u306f\u3001\u4e88\u671f\u305b\u306c\u526f\u4f5c\u7528\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u614e\u91cd\u306b\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u9ad8\u5ea6\u306a\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u7528\u3059\u308b\u969b\u306e\u6ce8\u610f\u70b9\u3084\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\" id=\"i-22\"><span class=\"sgb-heading__inner sgb-heading--type1 with-icon\" style=\"background-color:transparent;border-color:transparent;font-size:1.2em\"><i class=\"fa fa-check\" style=\"color:var(--wp--preset--color--sango-main)\"><\/i><span class=\"sgb-heading__text\" style=\"color:#333\">5. include\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3068\u6ce8\u610f\u70b9<\/span><\/span><\/h2>\n\n\n\n<p><code>include<\/code>\u306f\u5f37\u529b\u306a\u6a5f\u80fd\u3067\u3059\u304c\u3001\u4f7f\u7528\u3059\u308b\u969b\u306b\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff\u3068\u6f5c\u5728\u7684\u306a\u554f\u984c\u70b9\u3092\u7406\u89e3\u3057\u3066\u304a\u304f\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<br>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001<code>include<\/code>\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff\u3068\u3001\u4f7f\u7528\u6642\u306e\u6ce8\u610f\u70b9\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-23\">\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u3068\u5b9f\u884c\u901f\u5ea6\u3078\u306e\u5f71\u97ff<\/h3>\n\n\n\n<p><code>include<\/code>\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u30af\u30e9\u30b9\u306b\u8ffd\u52a0\u3055\u308c\u308b\u305f\u3081\u3001\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306b\u308f\u305a\u304b\u306a\u5f71\u97ff\u304c\u3042\u308a\u307e\u3059\u3002<br>\u307e\u305f\u3001\u30e1\u30bd\u30c3\u30c9\u63a2\u7d22\u306e\u6642\u9593\u304c\u82e5\u5e72\u5897\u52a0\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<br>\u3057\u304b\u3057\u3001\u3053\u308c\u3089\u306e\u5f71\u97ff\u306f\u901a\u5e38\u3001\u7121\u8996\u3067\u304d\u308b\u30ec\u30d9\u30eb\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">require 'benchmark'\n\nmodule LargeModule\n  1000.times do |i|\n    define_method(\"method_#{i}\") { i }\n  end\nend\n\nclass WithoutInclude\nend\n\nclass WithInclude\n  include LargeModule\nend\n\nBenchmark.bm do |x|\n  x.report(\"Without include:\") { WithoutInclude.new }\n  x.report(\"With include:   \") { WithInclude.new }\nend<\/pre>\n\n\n\n<p>\u3053\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001<code>include<\/code>\u3092\u4f7f\u7528\u3057\u305f\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u304c\u308f\u305a\u304b\u306b\u9045\u304f\u306a\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<br>\u305f\u3060\u3057\u3001\u5b9f\u969b\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3053\u306e\u5dee\u304c\u554f\u984c\u306b\u306a\u308b\u3053\u3068\u306f\u7a00\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-24\">\u6ce8\u610f\u70b9\u3068\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-25\">1. <strong>\u540d\u524d\u885d\u7a81\u306e\u56de\u907f<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u3068\u30e1\u30bd\u30c3\u30c9\u540d\u306e\u614e\u91cd\u306a\u9078\u629e<\/li>\n\n\n\n<li>\u540d\u524d\u7a7a\u9593\u306e\u9069\u5207\u306a\u4f7f\u7528<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   module MyApp\n     module StringUtils\n       def self.capitalize_words(str)\n         str.split.map(&amp;:capitalize).join(' ')\n       end\n     end\n   end<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-26\">2. <strong>\u7d99\u627f\u30c1\u30a7\u30fc\u30f3\u306e\u7ba1\u7406<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0d\u5fc5\u8981\u306b\u591a\u304f\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092<code>include<\/code>\u3057\u306a\u3044<\/li>\n\n\n\n<li>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u660e\u78ba\u306b<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-27\">3. <strong>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u91cd\u8981\u6027<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>include<\/code>\u3057\u305f\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u6a5f\u80fd\u3092\u660e\u78ba\u306b\u8a18\u8ff0<\/li>\n\n\n\n<li>\u6f5c\u5728\u7684\u306a\u526f\u4f5c\u7528\u3084\u5236\u9650\u4e8b\u9805\u3092\u8a18\u8f09<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-28\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316\u306e\u30d2\u30f3\u30c8<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5fc5\u8981\u6700\u5c0f\u9650\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u307f\u3092<code>include<\/code>\u3059\u308b<\/li>\n\n\n\n<li>\u5927\u898f\u6a21\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u306f\u5c0f\u3055\u306a\u5358\u4f4d\u306b\u5206\u5272\u3059\u308b<\/li>\n\n\n\n<li>\u30e1\u30bd\u30c3\u30c9\u547c\u3073\u51fa\u3057\u306e\u968e\u5c64\u3092\u6d45\u304f\u3059\u308b<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u6539\u5584\u524d\nmodule A\n  def method_a\n    # \u51e6\u7406\n  end\nend\n\nmodule B\n  include A\n  def method_b\n    method_a\n    # \u8ffd\u52a0\u306e\u51e6\u7406\n  end\nend\n\nclass MyClass\n  include B\nend\n\n# \u6539\u5584\u5f8c\nmodule OptimizedModule\n  def method_a\n    # \u51e6\u7406\n  end\n\n  def method_b\n    method_a\n    # \u8ffd\u52a0\u306e\u51e6\u7406\n  end\nend\n\nclass MyClass\n  include OptimizedModule\nend<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-29\">\u307e\u3068\u3081<\/h3>\n\n\n\n<p><code>include<\/code>\u306f\u5f37\u529b\u306a\u6a5f\u80fd\u3067\u3059\u304c\u3001\u9069\u5207\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<br>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff\u306f\u901a\u5e38\u5c0f\u3055\u3044\u3067\u3059\u304c\u3001\u5927\u898f\u6a21\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u8003\u616e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br>\u540d\u524d\u885d\u7a81\u3084\u7d99\u627f\u30c1\u30a7\u30fc\u30f3\u306e\u8907\u96d1\u5316\u306b\u6ce8\u610f\u3057\u3064\u3064\u3001\u9069\u5207\u306a\u8a2d\u8a08\u3068\u30c9\u30ad\u30e5\u30e1\u30f3\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u5fc3\u304c\u3051\u308b\u3053\u3068\u3067\u3001<code>include<\/code>\u306e\u5229\u70b9\u3092\u6700\u5927\u9650\u306b\u6d3b\u304b\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\" id=\"i-30\"><span class=\"sgb-heading__inner sgb-heading--type1 with-icon\" style=\"background-color:transparent;border-color:transparent;font-size:1.2em\"><i class=\"fa fa-check\" style=\"color:var(--wp--preset--color--sango-main)\"><\/i><span class=\"sgb-heading__text\" style=\"color:#333\">6. \u5b9f\u8df5\u6f14\u7fd2\uff1ainclude\u3092\u4f7f\u3063\u305f\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u4f8b<\/span><\/span><\/h2>\n\n\n\n<p>\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306f\u3001\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3084\u8907\u96d1\u6027\u304c\u5897\u3059\u306b\u3064\u308c\u3066\u3001\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u304c\u5fc5\u8981\u306b\u306a\u308b\u3053\u3068\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3002<br>\u3053\u3053\u3067\u306f\u3001<code>include<\/code>\u3092\u4f7f\u3063\u305f\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306e\u5b9f\u8df5\u4f8b\u3092\u901a\u3058\u3066\u3001\u30b3\u30fc\u30c9\u3092\u3088\u308a\u6574\u7406\u3055\u308c\u305f\u3001\u4fdd\u5b88\u6027\u306e\u9ad8\u3044\u3082\u306e\u306b\u6539\u5584\u3059\u308b\u65b9\u6cd5\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-31\">Before\uff1a\u30b9\u30d1\u30b2\u30c3\u30c6\u30a3\u30b3\u30fc\u30c9\u306e\u554f\u984c\u70b9<\/h3>\n\n\n\n<p>\u307e\u305a\u3001\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u524d\u306e\u554f\u984c\u306e\u3042\u308b\u30b3\u30fc\u30c9\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br>\u3053\u306e\u4f8b\u3067\u306f\u3001\u8907\u6570\u306e\u52d5\u7269\u30af\u30e9\u30b9\u304c\u4f3c\u305f\u3088\u3046\u306a\u6a5f\u80fd\u3092\u91cd\u8907\u3057\u3066\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class Dog\n  def initialize(name)\n    @name = name\n  end\n\n  def speak\n    puts \"#{@name} says Woof!\"\n  end\n\n  def eat\n    puts \"#{@name} is eating.\"\n  end\n\n  def sleep\n    puts \"#{@name} is sleeping.\"\n  end\nend\n\nclass Cat\n  def initialize(name)\n    @name = name\n  end\n\n  def speak\n    puts \"#{@name} says Meow!\"\n  end\n\n  def eat\n    puts \"#{@name} is eating.\"\n  end\n\n  def sleep\n    puts \"#{@name} is sleeping.\"\n  end\nend\n\nclass Bird\n  def initialize(name)\n    @name = name\n  end\n\n  def speak\n    puts \"#{@name} says Tweet!\"\n  end\n\n  def eat\n    puts \"#{@name} is eating.\"\n  end\n\n  def sleep\n    puts \"#{@name} is sleeping.\"\n  end\nend<\/pre>\n\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306e\u554f\u984c\u70b9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-message\"><div class=\"memo sng-shadow-0\" style=\"border-radius:0px;background-color:#ffebeb;color:#f88080\"><div class=\"memo_ttl dfont\"><span class=\"sng-box-msg__icon\" style=\"background:#f88080\"><i class=\"fas fa-exclamation\"><\/i><\/span><div class=\"sng-box-msg__title\">\u4e0a\u8a18\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u554f\u984c\u70b9<\/div><\/div><div class=\"sng-box-msg__contents\">\n<ol class=\"wp-block-list\">\n<li><strong>\u30b3\u30fc\u30c9\u306e\u91cd\u8907<\/strong>: <code>eat<\/code>\u3068<code>sleep<\/code>\u30e1\u30bd\u30c3\u30c9\u304c\u5168\u3066\u306e\u30af\u30e9\u30b9\u3067\u540c\u3058\u5b9f\u88c5\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u306e\u4f4e\u3055<\/strong>: \u5171\u901a\u306e\u52d5\u4f5c\u3092\u5909\u66f4\u3059\u308b\u5834\u5408\u3001\u5168\u3066\u306e\u30af\u30e9\u30b9\u3092\u500b\u5225\u306b\u4fee\u6b63\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u62e1\u5f35\u6027\u306e\u6b20\u5982<\/strong>: \u65b0\u3057\u3044\u52d5\u7269\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\u3059\u308b\u969b\u306b\u3001\u65e2\u5b58\u306e\u5168\u3066\u306e\u6a5f\u80fd\u3092\u518d\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n<\/ol>\n<\/div><\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-32\">\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306e\u30d7\u30ed\u30bb\u30b9<\/h3>\n\n\n\n<p>\u3067\u306f\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092<code>include<\/code>\u3092\u4f7f\u3063\u3066\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br>\u4ee5\u4e0b\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u9032\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5171\u901a\u6a5f\u80fd\u306e\u7279\u5b9a<\/li>\n\n\n\n<li>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u4f5c\u6210<\/li>\n\n\n\n<li>\u30af\u30e9\u30b9\u3078\u306e<code>include<\/code><\/li>\n\n\n\n<li>\u91cd\u8907\u30b3\u30fc\u30c9\u306e\u524a\u9664<\/li>\n\n\n\n<li>\u30c6\u30b9\u30c8\u3068\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-33\">After\uff1ainclude\u3092\u4f7f\u3063\u3066\u7f8e\u3057\u304f\u6574\u7406\u3055\u308c\u305f\u30b3\u30fc\u30c9<\/h3>\n\n\n\n<p>\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u5f8c\u306e\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module Animal\n  attr_reader :name\n\n  def initialize(name)\n    @name = name\n  end\n\n  def eat\n    puts \"#{name} is eating.\"\n  end\n\n  def sleep\n    puts \"#{name} is sleeping.\"\n  end\nend\n\nmodule Speakable\n  def speak\n    puts \"#{name} says #{sound}!\"\n  end\nend\n\nclass Dog\n  include Animal\n  include Speakable\n\n  def sound\n    \"Woof\"\n  end\nend\n\nclass Cat\n  include Animal\n  include Speakable\n\n  def sound\n    \"Meow\"\n  end\nend\n\nclass Bird\n  include Animal\n  include Speakable\n\n  def sound\n    \"Tweet\"\n  end\nend<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-34\">\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306b\u3088\u308b\u6539\u5584\u70b9<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u5411\u4e0a<\/strong>: \u5171\u901a\u306e<code>eat<\/code>\u3068<code>sleep<\/code>\u30e1\u30bd\u30c3\u30c9\u3092<code>Animal<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u307e\u3068\u3081\u308b\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3092\u6392\u9664\u3057\u307e\u3057\u305f\u3002<\/li>\n\n\n\n<li><strong>\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u306e\u5411\u4e0a<\/strong>: \u5171\u901a\u6a5f\u80fd\u306e\u5909\u66f4\u304c1\u7b87\u6240\u3067\u6e08\u3080\u3088\u3046\u306b\u306a\u308a\u3001\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/li>\n\n\n\n<li><strong>\u62e1\u5f35\u6027\u306e\u6539\u5584<\/strong>: \u65b0\u3057\u3044\u52d5\u7269\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\u3059\u308b\u969b\u3001\u5fc5\u8981\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u3092<code>include<\/code>\u3059\u308b\u3060\u3051\u3067\u57fa\u672c\u6a5f\u80fd\u304c\u5229\u7528\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u95a2\u5fc3\u306e\u5206\u96e2<\/strong>: <code>Speakable<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5225\u306b\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u3001\u767a\u58f0\u6a5f\u80fd\u3092\u6301\u3064\u52d5\u7269\u3068\u6301\u305f\u306a\u3044\u52d5\u7269\u3092\u67d4\u8edf\u306b\u5b9a\u7fa9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/li>\n\n\n\n<li><strong>\u30b3\u30fc\u30c9\u306e\u7c21\u6f54\u5316<\/strong>: \u5404\u52d5\u7269\u30af\u30e9\u30b9\u306e\u30b3\u30fc\u30c9\u304c\u5927\u5e45\u306b\u7c21\u7565\u5316\u3055\u308c\u3001\u30af\u30e9\u30b9\u56fa\u6709\u306e\u632f\u308b\u821e\u3044\u306b\u96c6\u4e2d\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-35\">\u5b9f\u8df5\u7684\u306a\u30b7\u30ca\u30ea\u30aa<\/h3>\n\n\n\n<p>\u3053\u306e\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u4f8b\u306f\u3001\u30b2\u30fc\u30e0\u958b\u767a\u3084\u751f\u7269\u5b66\u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u306a\u3069\u3001\u591a\u69d8\u306a\u52d5\u7269\u306e\u632f\u308b\u821e\u3044\u3092\u30e2\u30c7\u30eb\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u9762\u3067\u7279\u306b\u6709\u52b9\u3067\u3059\u3002<br>\u4f8b\u3048\u3070\u3001\u65b0\u3057\u304f\u6c34\u751f\u52d5\u7269\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module Swimmable\n  def swim\n    puts \"#{name} is swimming.\"\n  end\nend\n\nclass Fish\n  include Animal\n  include Speakable\n  include Swimmable\n\n  def sound\n    \"Blub\"\n  end\nend<\/pre>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u5fc5\u8981\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u3092<code>include<\/code>\u3059\u308b\u3060\u3051\u3067\u3001\u65e2\u5b58\u306e\u6a5f\u80fd\u3092\u518d\u5229\u7528\u3057\u3064\u3064\u65b0\u3057\u3044\u6a5f\u80fd\u3092\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-36\">\u307e\u3068\u3081<\/h3>\n\n\n\n<p><code>include<\/code>\u3092\u4f7f\u3063\u305f\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u30e1\u30ea\u30c3\u30c8\u304c\u5f97\u3089\u308c\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u304c\u524a\u6e1b\u3055\u308c\u3001DRY\uff08Don\u2019t Repeat Yourself\uff09\u306e\u539f\u5247\u306b\u5f93\u3063\u305f\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/li>\n\n\n\n<li>\u6a5f\u80fd\u306e\u8ffd\u52a0\u3084\u5909\u66f4\u304c\u5bb9\u6613\u306b\u306a\u308a\u3001\u5c06\u6765\u306e\u62e1\u5f35\u6027\u304c\u5411\u4e0a\u3057\u307e\u3057\u305f\u3002<\/li>\n\n\n\n<li>\u30b3\u30fc\u30c9\u306e\u69cb\u9020\u304c\u660e\u78ba\u306b\u306a\u308a\u3001\u5404\u90e8\u5206\u306e\u5f79\u5272\u304c\u7406\u89e3\u3057\u3084\u3059\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306a\u5b9f\u8df5\u7684\u306a\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3092\u901a\u3058\u3066\u3001<code>include<\/code>\u306e\u5f37\u529b\u3055\u3068\u67d4\u8edf\u6027\u3092\u5b9f\u611f\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<br>\u65e5\u3005\u306e\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3067\u3082\u3001\u4f3c\u305f\u3088\u3046\u306a\u30d1\u30bf\u30fc\u30f3\u3092\u898b\u3064\u3051\u305f\u3089\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u5316\u3068<code>include<\/code>\u306e\u4f7f\u7528\u3092\u691c\u8a0e\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\" id=\"i-37\"><span class=\"sgb-heading__inner sgb-heading--type1 with-icon\" style=\"background-color:transparent;border-color:transparent;font-size:1.2em\"><i class=\"fa fa-check\" style=\"color:var(--wp--preset--color--sango-main)\"><\/i><span class=\"sgb-heading__text\" style=\"color:#333\">7. \u307e\u3068\u3081\uff1ainclude\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053<\/span><\/span><\/h2>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3092\u901a\u3058\u3066\u3001Ruby\u306e<code>include<\/code>\u306e\u57fa\u672c\u304b\u3089\u9ad8\u5ea6\u306a\u4f7f\u7528\u6cd5\u307e\u3067\u3001\u5e45\u5e83\u304f\u5b66\u3093\u3067\u304d\u307e\u3057\u305f\u3002<br>\u3053\u3053\u3067\u306f\u3001\u3053\u308c\u307e\u3067\u306e\u5185\u5bb9\u3092\u632f\u308a\u8fd4\u308a\u3001<code>include<\/code>\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\u7b4b\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-38\">include\u306e\u4f7f\u3044\u3053\u306a\u3057\u3067\u5f97\u3089\u308c\u308b3\u3064\u306e\u6210\u679c<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-39\">1. <strong>\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u3068\u4fdd\u5b88\u6027\u306e\u5411\u4e0a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u5171\u901a\u6a5f\u80fd\u3092\u52b9\u7387\u7684\u306b\u7ba1\u7406\u3057\u3001\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3092\u524a\u6e1b\u3067\u304d\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u6a5f\u80fd\u306e\u5909\u66f4\u3084\u4fee\u6b63\u304c\u4e00\u7b87\u6240\u3067\u6e08\u3080\u305f\u3081\u3001\u9577\u671f\u7684\u306a\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-40\">2. <strong>\u67d4\u8edf\u306a\u6a5f\u80fd\u62e1\u5f35\u3068\u8a2d\u8a08\u306e\u5b9f\u73fe<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8907\u6570\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u67d4\u8edf\u306a\u30af\u30e9\u30b9\u8a2d\u8a08\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u5358\u4e00\u7d99\u627f\u306e\u5236\u9650\u3092\u8d85\u3048\u3066\u3001\u5fc5\u8981\u306a\u6a5f\u80fd\u3060\u3051\u3092\u9078\u629e\u7684\u306b\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-41\">3. <strong>\u30af\u30ea\u30fc\u30f3\u3067\u8aad\u307f\u3084\u3059\u3044\u30b3\u30fc\u30c9\u306e\u4f5c\u6210<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u95a2\u9023\u3059\u308b\u6a5f\u80fd\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u307e\u3068\u3081\u308b\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u306e\u69cb\u9020\u304c\u660e\u78ba\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li>\u540d\u524d\u7a7a\u9593\u306e\u9069\u5207\u306a\u4f7f\u7528\u306b\u3088\u308a\u3001\u5927\u898f\u6a21\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3082\u6574\u7406\u3055\u308c\u305f\u30b3\u30fc\u30c9\u3092\u7dad\u6301\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-42\">\u3055\u3089\u306a\u308b\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3068\u6b21\u306e\u30b9\u30c6\u30c3\u30d7<\/h3>\n\n\n\n<p><code>include<\/code>\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\u306f\u3001\u3053\u3053\u3067\u7d42\u308f\u308a\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3055\u3089\u306a\u308b\u9ad8\u307f\u3092\u76ee\u6307\u3059\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u30ea\u30bd\u30fc\u30b9\u3068\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/ruby-doc.org\/\">Ruby\u306e\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u3067\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3068<code>include<\/code>\u306b\u95a2\u3059\u308b\u8a73\u7d30\u306a\u60c5\u5831\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/guides.rubyonrails.org\/\">Ruby on Rails Guides<\/a>\u3067\u3001\u5b9f\u969b\u306eWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u306b\u304a\u3051\u308b<code>include<\/code>\u306e\u4f7f\u7528\u4f8b\u3092\u5b66\u3076\u3002<\/li>\n\n\n\n<li>\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30fc\u30c9\u3092\u5206\u6790\u3057\u3001\u5b9f\u8df5\u7684\u306a<code>include<\/code>\u306e\u4f7f\u7528\u30d1\u30bf\u30fc\u30f3\u3092\u5b66\u3076\u3002<\/li>\n\n\n\n<li>Ruby\u306b\u95a2\u3059\u308b\u6280\u8853\u66f8\u3084\u5c02\u9580\u30d6\u30ed\u30b0\u3092\u5b9a\u671f\u7684\u306b\u8aad\u307f\u3001\u6700\u65b0\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u628a\u63e1\u3059\u308b\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3068\u3057\u3066\u306f\u3001\u4ee5\u4e0b\u306e\u70b9\u306b\u53d6\u308a\u7d44\u3080\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-43\">1. <strong>\u4ed6\u306eRuby\u306e\u9ad8\u5ea6\u306a\u6a5f\u80fd\u306e\u5b66\u7fd2<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3084\u52d5\u7684\u30e1\u30bd\u30c3\u30c9\u5b9a\u7fa9\u306a\u3069\u3001Ruby\u306e\u4ed6\u306e\u9ad8\u5ea6\u306a\u6a5f\u80fd\u3068<code>include<\/code>\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u63a2\u6c42\u3059\u308b\u3002<\/li>\n\n\n\n<li>\u30d7\u30ed\u30ad\u30b7\u30d1\u30bf\u30fc\u30f3\u3084\u30c7\u30b3\u30ec\u30fc\u30bf\u30d1\u30bf\u30fc\u30f3\u306a\u3069\u3001<code>include<\/code>\u3092\u6d3b\u7528\u3057\u305f\u30c7\u30b6\u30a4\u30f3\u30d1\u30bf\u30fc\u30f3\u306e\u5b9f\u88c5\u3092\u8a66\u307f\u308b\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-44\">2. <strong>\u30c7\u30b6\u30a4\u30f3\u30d1\u30bf\u30fc\u30f3\u3068\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u95a2\u4fc2\u306e\u63a2\u6c42<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>GoF\u306e\u30c7\u30b6\u30a4\u30f3\u30d1\u30bf\u30fc\u30f3\u3092Ruby\u3067\u5b9f\u88c5\u3059\u308b\u969b\u306b\u3001<code>include<\/code>\u304c\u3069\u306e\u3088\u3046\u306b\u6d3b\u7528\u3067\u304d\u308b\u304b\u7814\u7a76\u3059\u308b\u3002<\/li>\n\n\n\n<li>\u30e2\u30b8\u30e5\u30fc\u30eb\u30d9\u30fc\u30b9\u306e\u8a2d\u8a08\u3068\u5f93\u6765\u306e\u30af\u30e9\u30b9\u7d99\u627f\u30d9\u30fc\u30b9\u306e\u8a2d\u8a08\u3092\u6bd4\u8f03\u3057\u3001\u305d\u308c\u305e\u308c\u306e\u9577\u6240\u3068\u77ed\u6240\u3092\u7406\u89e3\u3059\u308b\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-45\">3. <strong>\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306e\u7a4d\u6975\u7684\u306a\u6d3b\u7528<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u81ea\u5206\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067<code>include<\/code>\u3092\u7a4d\u6975\u7684\u306b\u4f7f\u7528\u3057\u3001\u5b9f\u8df5\u7684\u306a\u7d4c\u9a13\u3092\u7a4d\u3080\u3002<\/li>\n\n\n\n<li>\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3092\u901a\u3058\u3066\u3001\u4ed6\u306e\u958b\u767a\u8005\u304b\u3089\u30d5\u30a3\u30fc\u30c9\u30d0\u30c3\u30af\u3092\u5f97\u308b\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-46\">\u6700\u5f8c\u306b<\/h3>\n\n\n\n<p><code>include<\/code>\u306e\u4f7f\u3044\u3053\u306a\u3057\u306f\u3001Ruby\u30de\u30b9\u30bf\u30fc\u3078\u306e\u91cd\u8981\u306a\u30b9\u30c6\u30c3\u30d7\u306e\u4e00\u3064\u3067\u3059\u3002<br>\u3053\u306e\u8a18\u4e8b\u3067\u5b66\u3093\u3060\u5185\u5bb9\u3092\u5b9f\u8df5\u3057\u3001\u7d99\u7d9a\u7684\u306b\u5b66\u7fd2\u3092\u91cd\u306d\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u67d4\u8edf\u3067\u4fdd\u5b88\u6027\u306e\u9ad8\u3044Ruby\u30b3\u30fc\u30c9\u3092\u66f8\u3051\u308b\u3088\u3046\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>Ruby\u958b\u767a\u306e\u7d20\u6674\u3089\u3057\u3044\u4e16\u754c\u3067\u306e\u5192\u967a\u3092\u697d\u3057\u3093\u3067\u304f\u3060\u3055\u3044\u3002<br><code>include<\/code>\u3092\u901a\u3058\u3066\u3001\u3042\u306a\u305f\u306e\u30b3\u30fc\u30c9\u304c\u3088\u308a\u8868\u73fe\u529b\u8c4a\u304b\u3067\u52b9\u7387\u7684\u306b\u306a\u308b\u3053\u3068\u3092\u9858\u3063\u3066\u3044\u307e\u3059\u3002<br>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ruby\u306einclude\u306f\u3001\u30b3\u30fc\u30c9\u306e\u518d\u5229\u7528\u6027\u3068\u67d4\u8edf\u6027\u3092\u9ad8\u3081\u308b\u5f37\u529b\u306a\u6a5f\u80fd\u3067\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001include\u306e\u57fa\u672c\u304b\u3089\u9ad8\u5ea6\u306a\u4f7f\u7528\u6cd5\u307e\u3067\u3001\u5b9f\u8df5\u7684\u306a\u4f8b\u3092\u4ea4\u3048\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002\u521d\u5fc3\u8005\u304b\u3089\u4e2d\u7d1a\u8005\u307e\u3067\u3001Ruby\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u306e\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u306b &#8230; <\/p>\n","protected":false},"author":1,"featured_media":3095,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,65],"tags":[],"class_list":{"0":"post-133","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ruby","8":"category-ruby-syntax"},"_links":{"self":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=133"}],"version-history":[{"count":3,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":3122,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/133\/revisions\/3122"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/media\/3095"}],"wp:attachment":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}