回答編集履歴
2
コード追記
answer
CHANGED
@@ -15,4 +15,21 @@
|
|
15
15
|
|
16
16
|
ただ、これだとnilが出力されないです。
|
17
17
|
>50
|
18
|
-
>50
|
18
|
+
>50
|
19
|
+
|
20
|
+
無理矢理nilを出力させようとするならこんな感じでしょうか。
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
def area(x,y)x*y if x end
|
24
|
+
|
25
|
+
class Rect
|
26
|
+
def initialize(x,y)@x,@y=x,y end
|
27
|
+
attr_reader :x,:y
|
28
|
+
def area()x*y if x end
|
29
|
+
end
|
30
|
+
|
31
|
+
puts area(nil,nil)
|
32
|
+
puts Rect.new(nil,nil).area
|
33
|
+
puts area(10,5)
|
34
|
+
puts Rect.new(10,5).area
|
35
|
+
```
|
1
インデント編集
answer
CHANGED
@@ -5,10 +5,9 @@
|
|
5
5
|
def area(x,y)x*y end
|
6
6
|
|
7
7
|
class Rect
|
8
|
-
|
9
8
|
def initialize(x,y)@x,@y=x,y end
|
10
|
-
|
9
|
+
attr_reader :x,:y
|
11
|
-
|
10
|
+
def area()x*y end
|
12
11
|
end
|
13
12
|
puts area(10,5)
|
14
13
|
puts Rect.new(10,5).area
|