回答編集履歴

3

Update

2021/11/30 18:23

投稿

melian
melian

スコア19840

test CHANGED
@@ -60,13 +60,11 @@
60
60
 
61
61
  # testing
62
62
 
63
- ["A", "B", "C", "D", "String", "", 1, true, nil].each{|input|
63
+ ["A", "B", "C", "D", "Parent", "String", "", 1, true, nil].each{|input|
64
64
 
65
- output = (Class.const_defined?(input) rescue nil) &&
65
+ output = ((Class.const_get(input) < Parent rescue false) || nil) &&
66
66
 
67
- Class.const_get(input) < Parent &&
68
-
69
- Class.const_get(input).new.greeting
67
+ Class.const_get(input).new.greeting
70
68
 
71
69
  printf("%8p: %p\n", input, output)
72
70
 
@@ -76,13 +74,15 @@
76
74
 
77
75
  #
78
76
 
79
- "A": "Hi, I'm A, now 1970-01-01 00:00:00."
77
+ "A": "Hi, I'm A, now 2021-12-01 03:21:21 +0900."
80
78
 
81
- "B": "Hi, I'm B, rolling dice and got 1."
79
+ "B": "Hi, I'm B, rolling dice and got 2."
82
80
 
83
81
  "C": "Hi, I'm C, 1 + 1 = 2 // Q.E.D."
84
82
 
85
83
  "D": nil
84
+
85
+ "Parent": nil
86
86
 
87
87
  "String": nil
88
88
 

2

Update

2021/11/30 18:23

投稿

melian
melian

スコア19840

test CHANGED
@@ -52,34 +52,46 @@
52
52
 
53
53
 
54
54
 
55
- input = "A"
55
+ class D
56
56
 
57
- puts (Object.const_defined?(input) rescue false) &&
57
+ end
58
-
59
- Class.const_get(input) < Parent && Class.const_get(input).new.greeting
60
58
 
61
59
 
62
60
 
63
- input = "B"
61
+ # testing
64
62
 
65
- puts (Object.const_defined?(input) rescue false) &&
63
+ ["A", "B", "C", "D", "String", "", 1, true, nil].each{|input|
66
64
 
65
+ output = (Class.const_defined?(input) rescue nil) &&
66
+
67
- Class.const_get(input) < Parent && Class.const_get(input).new.greeting
67
+ Class.const_get(input) < Parent &&
68
+
69
+ Class.const_get(input).new.greeting
70
+
71
+ printf("%8p: %p\n", input, output)
72
+
73
+ }
68
74
 
69
75
 
70
76
 
71
- input = "C"
77
+ #
72
78
 
73
- puts (Object.const_defined?(input) rescue false) &&
79
+ "A": "Hi, I'm A, now 1970-01-01 00:00:00."
74
80
 
75
- Class.const_get(input) < Parent && Class.const_get(input).new.greeting
81
+ "B": "Hi, I'm B, rolling dice and got 1."
76
82
 
83
+ "C": "Hi, I'm C, 1 + 1 = 2 // Q.E.D."
77
84
 
85
+ "D": nil
78
86
 
79
- input = "D"
87
+ "String": nil
80
88
 
81
- puts (Object.const_defined?(input) rescue false) &&
89
+ "": nil
82
90
 
91
+ 1: nil
92
+
83
- Class.const_get(input) < Parent && Class.const_get(input).new.greeting
93
+ true: nil
94
+
95
+ nil: nil
84
96
 
85
97
  ```

1

Update

2021/11/30 18:03

投稿

melian
melian

スコア19840

test CHANGED
@@ -54,32 +54,32 @@
54
54
 
55
55
  input = "A"
56
56
 
57
+ puts (Object.const_defined?(input) rescue false) &&
58
+
57
- puts Class.const_defined?(input) && Class.const_get(input).new.greeting
59
+ Class.const_get(input) < Parent && Class.const_get(input).new.greeting
58
60
 
59
61
 
60
62
 
61
63
  input = "B"
62
64
 
65
+ puts (Object.const_defined?(input) rescue false) &&
66
+
63
- puts Class.const_defined?(input) && Class.const_get(input).new.greeting
67
+ Class.const_get(input) < Parent && Class.const_get(input).new.greeting
64
68
 
65
69
 
66
70
 
67
71
  input = "C"
68
72
 
73
+ puts (Object.const_defined?(input) rescue false) &&
74
+
69
- puts Class.const_defined?(input) && Class.const_get(input).new.greeting
75
+ Class.const_get(input) < Parent && Class.const_get(input).new.greeting
70
76
 
71
77
 
72
78
 
73
79
  input = "D"
74
80
 
75
- puts Class.const_defined?(input) && Class.const_get(input).new.greeting
81
+ puts (Object.const_defined?(input) rescue false) &&
76
82
 
77
-
78
-
79
- #["A", "B", "C", "D"].each{|i|
80
-
81
- # puts Class.const_defined?(i) && Class.const_get(i).new.greeting
83
+ Class.const_get(input) < Parent && Class.const_get(input).new.greeting
82
-
83
- #}
84
84
 
85
85
  ```