[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: shortcut for x = [x] unless x.is_a?(Array

Paul Mckibbin

3/10/2008 11:09:00 PM

Aryk Grosz wrote:
> Is there any prettier or cleaner way to write
>
> x = [x] unless x.is_a?(Array)

Lots of caveats, caution and make sure you really, really are thinking
about what you are trying to do. But with that note of skepticism
aside.......

I'd guess what you really want is:

x=Array(x)

This will give you the same behaviour for String, Fixnum, TrueClass,
Regexp and Array as your line, and is probably more what you want for
Nil, Range and Hash. I'm second guessing, but this may not be the wisest
way of writing your code.

Are you trying to get around the fact that x=x.to_a default behavior
will be obsoleted in v1.9?

Make sure that is really what you want.

The answer depends on what you are trying to convert from. I'd use
something like this to make sure this is really what you want to
achieve.

TEST=[[1,2,3],(1..3),{:a=>:b},1,"test",true,nil,/123/]

TEST.each do |x|
puts x.class
puts '============================'
puts "#{x.inspect}.to_a => #{x.to_a.inspect}"
puts "[#{x.inspect}] => #{([x]).inspect}"
puts "Array(#{x.inspect}) => #{Array(x).inspect}"
puts '============================'
end


OUTPUT
============================
[1, 2, 3].to_a => [1, 2, 3]
[[1, 2, 3]] => [[1, 2, 3]] <----- this seems to be the only
case that you are catering for
Array([1, 2, 3]) => [1, 2, 3]
============================
Range
============================
1..3.to_a => [1, 2, 3]
[1..3] => [1..3]
Array(1..3) => [1, 2, 3]
============================
Hash
============================
{:a=>:b}.to_a => [[:a, :b]]
[{:a=>:b}] => [{:a=>:b}]
Array({:a=>:b}) => [[:a, :b]]
============================
Fixnum
============================
1.to_a => [1]
[1] => [1]
Array(1) => [1]
============================
String
============================
"test".to_a => ["test"]
["test"] => ["test"]
Array("test") => ["test"]
============================
TrueClass
============================
true.to_a => [true]
[true] => [true]
Array(true) => [true]
============================
NilClass
============================
nil.to_a => []
[nil] => [nil]
Array(nil) => []
============================
Regexp
============================
/123/.to_a => [/123/]
[/123/] => [/123/]
Array(/123/) => [/123/]
============================
--
Posted via http://www.ruby-....

2 Answers

Frank R.

11/20/2010 3:21:00 AM

0

Sorry John if I sounded harsh, and I did really think you were referring
to North Star but I honestly have never heard of plastic posts on North
Star. I'd like to go farther to say that this isn't just my opinion, but
factual since that era of Gottlieb games (beginning with World Fair) had
metal posts. Gottlieb used colored plastic posts on their earlier games
(i.e. Flipper Cowboy as you know) but abandoned them by '64 when North Star
was produced. They never mixed metal and plastic posts either.
Later on, when either they found the cost of metal posts too prohibitive
or they simply ran out of them they alternated metal posts between the
replay and add-a-ball models - hence King of Diamonds had metal posts while
Diamond Jack had plastic ones. Then, they alternated by putting metal posts
on Melody and plastic ones on Sing Along. Eventually, they went to white
plastic posts from the late 60's all the way to the end.
BTW, I really enjoyed your pictures. Very nice games and wonderful work.
I restored a Flipper Cowboy myself and was very pleased with the results. I
also have a North Star (with all metal posts of course).

Frank R.

"jon allison" <whytattooyou@gmail.com> wrote in message
news:0cc271d3-9a26-47b0-9fd4-d8ad5f439af3@g16g2000yqb.googlegroups.com...
On Nov 19, 4:47 pm, "Frank R." <frankjea...@frontiernet.net> wrote:
> Which game are you talking about, the North Star or the Flipper Cowboy?
> It really doesn't matter since I can easily answer your question either
way.
> North Star has no plastic posts and Flipper Cowboy has no metal posts. I
> have never seen a North Star (even in photos) which has plastic posts.
>
> Frank R.
>
> "jon allison" <whytattoo...@gmail.com> wrote in message
>
> news:cf7ed01f-b428-4e98-9888-08a3a2791717@r29g2000yqj.googlegroups.com...
>
> > I recently finished a complete overhaul on the above game
> >http://s739.photobucket.com/home/whytatto...
> > but I have this question regarding the metal posts.Every picture I
> > have seen of this game shows
> > two blue plastic posts on the bottom left/right plastics.All the rest
> > are the metal ones.I was told by
> > an individual on good authority that he had consulted with person who
> > owns two of these games
> > and they should be metal.Right now there is one on Ebay and it also
> > has the two plastic posts.
> > Does anyone have the game and what is the consensus on which posts
> > those two should be ?

Frank
I think the original question title explained as to which
game I was talking about.If you look at the two bottom posts
on NS you will see that they are blue plastic.Check this link also
http://cgi.ebay.com/ws/eBayISAPI.dll?VISuperSize&item=15.... As
you can see the bottom post is blue just like every other
picture I had seen of this game.Also look on pinball database and you
will see the same
http://www.ipdb.org/showpic.pl?id=1683&picno=22532&... I was
only looking for opinions



Ron, (Boatcat)

11/20/2010 1:06:00 PM

0


I've had 2 Northstars in my possession
at one time or another. Both had the blue posts
used at the bottom right and left corners under the
plastics.
Several other metal post games have
used plastic posts in positions it appears Gtb. felt
were hidden under plastics, such as wrap-around
rubber configs on King of Diamonds, (behind the
roto, and also behind the Ace Target), and
Crosstown, (behind the center target).