E
Eric Will
I've encountered this in the past and thought I was messing something
up, but it's happening still.
Can anyone tell me why this:
puts "ruby-#{RUBY_VERSION} [#{RUBY_PLATFORM}]"
[String, Array, Hash].each do |klass|
case klass
when String
puts "String!"
when Array
puts "Array!"
when Hash
puts "Hash!"
else
puts "I don't know: #{klass}"
end
end
Produces this:
ruby-1.8.7 [x86_64-linux]
I don't know: String
I don't know: Array
I don't know: Hash
ruby-1.9.1 [x86_64-linux]
I don't know: String
I don't know: Array
I don't know: Hash
Am I missing something here? In order to get the expected result I
have to do this:
[String, Array, Hash].each do |klass|
case klass.to_s
when "String"
puts "String!"
when "Array"
puts "Array!"
when "Hash"
puts "Hash!"
else
puts "I don't know: #{klass}"
end
end
This works of course, but why doesn't the former? I find it hard to
believe this has been overlooked. What am I missing?
-- Eric Will
up, but it's happening still.
Can anyone tell me why this:
puts "ruby-#{RUBY_VERSION} [#{RUBY_PLATFORM}]"
[String, Array, Hash].each do |klass|
case klass
when String
puts "String!"
when Array
puts "Array!"
when Hash
puts "Hash!"
else
puts "I don't know: #{klass}"
end
end
Produces this:
ruby-1.8.7 [x86_64-linux]
I don't know: String
I don't know: Array
I don't know: Hash
ruby-1.9.1 [x86_64-linux]
I don't know: String
I don't know: Array
I don't know: Hash
Am I missing something here? In order to get the expected result I
have to do this:
[String, Array, Hash].each do |klass|
case klass.to_s
when "String"
puts "String!"
when "Array"
puts "Array!"
when "Hash"
puts "Hash!"
else
puts "I don't know: #{klass}"
end
end
This works of course, but why doesn't the former? I find it hard to
believe this has been overlooked. What am I missing?
-- Eric Will