回答編集履歴

2

修正

2019/07/12 07:02

投稿

rhiroe
rhiroe

スコア2344

test CHANGED
@@ -46,8 +46,32 @@
46
46
 
47
47
  def self.mail_by_role(param)
48
48
 
49
- # self は 不要、 where pluck を使って1行で書けます
49
+ where(role: professions[param]).pluck(:mail)
50
50
 
51
51
  end
52
52
 
53
53
  ```
54
+
55
+
56
+
57
+ もしくは
58
+
59
+
60
+
61
+ ```rb
62
+
63
+ enum role: { director: 0, software_engineer: 1, hardware_engineer: 2, designer: 3, sales: 4, customer_relation: 5 }
64
+
65
+
66
+
67
+ def self.mail_by_role(param)
68
+
69
+ where(role: param).pluck(:mail)
70
+
71
+ end
72
+
73
+ ```
74
+
75
+
76
+
77
+ こちらの方が望ましい。

1

修正

2019/07/12 07:02

投稿

rhiroe
rhiroe

スコア2344

test CHANGED
@@ -46,9 +46,7 @@
46
46
 
47
47
  def self.mail_by_role(param)
48
48
 
49
- # self は 不要です。
50
-
51
- # where と pluck を使って1行で書けます
49
+ # self は 不要、 where と pluck を使って1行で書けます
52
50
 
53
51
  end
54
52