From: Michael Randall Date: 2009-10-27T04:44:54+09:00 Subject: Re: Array#collect in a method call, not working for me OK, I *thought* that part was working, but now I see that it wasn't really. So to help me understand I wrote the following, to see what it does and I see that adding the #inspect will give me the string to compare against. But does that mean that (a = [1, 2].class) is setting a to be an Array? Oh, and thank you! Here is my test... irb(main):034:0* def proovy( n ) irb(main):035:1> a = n.class.inspect irb(main):036:1> b = n.class irb(main):037:1> puts "a: #{a}" irb(main):038:1> puts "b: #{b}" irb(main):039:1> case a irb(main):040:2> when "Array" : puts "a matched Array in case" irb(main):041:2> when "Fixnum" : puts "a matched Fixnum in case" irb(main):042:2> end irb(main):043:1> case b irb(main):044:2> when "Array" : puts "b matched Array in case" irb(main):045:2> when "Fixnum" : puts "b matched Fixnum in case" irb(main):046:2> end irb(main):047:1> end => nil irb(main):048:0> proovy(1) a: Fixnum b: Fixnum a matched Fixnum in case => nil irb(main):049:0> proovy([1, 2, 3]) a: Array b: Array a matched Array in case => nil Robert Klemme wrote: > 2009/10/26 Michael Randall : >> I've attached my test code, "simplea.rb", and below is the output when I >> Test double( 3 ) >> >> Attachments: >> http://www.ruby-forum.com/attachment/4184/simplea.rb > > There are a few issues with the first line: > > my_a = [ n ].to_a unless n.class == "Array" > > First, the test will always fail because the class and the name of the > class are of different types: > > irb(main):002:0> Array == "Array" > => false > [ ... ] > robert -- Posted via http://www.ruby-forum.com/.