回答編集履歴

3

修正

2017/07/04 13:56

投稿

退会済みユーザー
test CHANGED
@@ -85,3 +85,33 @@
85
85
  ```
86
86
 
87
87
  外からfooを入れるバージョン。
88
+
89
+ ```Ruby
90
+
91
+ module M
92
+
93
+ def foo
94
+
95
+ puts $Const
96
+
97
+ end
98
+
99
+ end
100
+
101
+
102
+
103
+ class Foo
104
+
105
+ $Const = 'foo'
106
+
107
+ include M
108
+
109
+ end
110
+
111
+
112
+
113
+ Foo.new.foo
114
+
115
+ ```
116
+
117
+ グローバル変数で貫通させる。

2

修正

2017/07/04 13:56

投稿

退会済みユーザー
test CHANGED
@@ -57,3 +57,31 @@
57
57
  ```
58
58
 
59
59
  moduleの中にConstを入れてみました。
60
+
61
+ ```Ruby
62
+
63
+ module M
64
+
65
+ def foo(const)
66
+
67
+ puts const
68
+
69
+ end
70
+
71
+ end
72
+
73
+
74
+
75
+ class Foo
76
+
77
+ include M
78
+
79
+ end
80
+
81
+
82
+
83
+ Foo.new.foo('foo')
84
+
85
+ ```
86
+
87
+ 外からfooを入れるバージョン。

1

修正

2017/07/04 13:51

投稿

退会済みユーザー
test CHANGED
@@ -25,3 +25,35 @@
25
25
  ```
26
26
 
27
27
  class FooのConstを削除したらいけました。
28
+
29
+ #勘違いでした
30
+
31
+ ```Ruby
32
+
33
+ module M
34
+
35
+ Const = "foo"
36
+
37
+ def foo
38
+
39
+ puts Const
40
+
41
+ end
42
+
43
+ end
44
+
45
+
46
+
47
+ class Foo
48
+
49
+ include M
50
+
51
+ end
52
+
53
+
54
+
55
+ Foo.new.foo
56
+
57
+ ```
58
+
59
+ moduleの中にConstを入れてみました。