P
Phil Meier
Hello
I do not understand the following code:
======
file = File.open('test.txt', 'r')
hash = {'file' => file, 'title' => 'title'}
hash.map { | param_key, param_value |
puts "param_key = #{param_key}"
puts "param_value = #{param_value}"
puts "(param_value === String) = #{(param_value === String)}"
case param_value
when String
puts "This is a String!"
when File
puts "This is a File!"
else
puts "Neither String nor File!!!"
end
}
file.close
===
When I run this code the output is as follows:
param_key = title
param_value = title
(param_value === String) = false
This is a String!
param_key = file
param_value = #<File:0x2b689b8>
(param_value === String) = false
This is a File!
Why does Ruby goes to the when String case even if (param_value ===
String) is false?
BR Phil
I do not understand the following code:
======
file = File.open('test.txt', 'r')
hash = {'file' => file, 'title' => 'title'}
hash.map { | param_key, param_value |
puts "param_key = #{param_key}"
puts "param_value = #{param_value}"
puts "(param_value === String) = #{(param_value === String)}"
case param_value
when String
puts "This is a String!"
when File
puts "This is a File!"
else
puts "Neither String nor File!!!"
end
}
file.close
===
When I run this code the output is as follows:
param_key = title
param_value = title
(param_value === String) = false
This is a String!
param_key = file
param_value = #<File:0x2b689b8>
(param_value === String) = false
This is a File!
Why does Ruby goes to the when String case even if (param_value ===
String) is false?
BR Phil