[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Ruby wishlist

jzakiya

6/8/2008 3:19:00 AM

You can do this:

n1, n2, n3, n4 = nil

But you can't do this:

n1, n2, n3, n4 = [something]

And you can't do this:

n1, n2, n3, n4 [+,-,*, etc]= [something]

I really wish you could. I would make some of my
code so much more simple and concise.

Make the software work more for the user, and not the other
way around.
21 Answers

Rimantas Liubertas

6/8/2008 3:35:00 AM

0

> But you can't do this:
>
> n1, n2, n3, n4 = [something]

Just add one simbol and you can:

$ irb --simple-prompt
>> n1, n2, n3, n4 = *[1, 2, 3, 4]
=> [1, 2, 3, 4]
>> n1
=> 1
>> n2
=> 2
>> n3
=> 3
>> n4
=> 4

> And you can't do this:
>
> n1, n2, n3, n4 [+,-,*, etc]= [something]

Not sure what you want here.

<...> Make the software work more for the user, and not the other
> way around.

Make sure you know the software.


Regards,
Rimantas
--
http://rim...

jzakiya

6/8/2008 4:00:00 AM

0

On Jun 7, 11:35 pm, Rimantas Liubertas <riman...@gmail.com> wrote:
> > But you can't do this:
>
> > n1, n2, n3, n4 = [something]
>
> Just add one simbol and you can:
>
> $ irb --simple-prompt>> n1, n2, n3, n4 = *[1, 2, 3, 4]
> => [1, 2, 3, 4]
> >> n1
> => 1
> >> n2
> => 2
> >> n3
> => 3
> >> n4
>
> => 4
>
> > And you can't do this:
>
> > n1, n2, n3, n4 [+,-,*, etc]= [something]
>
> Not sure what you want here.
>
> <...> Make the software work more for the user, and not the other
>
> > way around.
>
> Make sure you know the software.
>
> Regards,
> Rimantas
> --http://rim...

Sorry for the confusion.

I want to set multiple variable to the same value:

n1, n2, n3, n4 = 5

and do +=, -=, *=, etc with the same value

n1, n2, n3, n4 += 5

instead of

n1 += 9; n2 += 9; n3 += 9; n4 += 9

It would soooo much more expressive, and concise.

David Masover

6/8/2008 5:30:00 AM

0

On Saturday 07 June 2008 23:03:47 jzakiya wrote:
> On Jun 7, 11:35 pm, Rimantas Liubertas <riman...@gmail.com> wrote:

> > $ irb --simple-prompt>> n1, n2, n3, n4 = *[1, 2, 3, 4]

Probably easier to simply do

n1, n2, n3, n4 = 1, 2, 3, 4

But I'm not sure that's what you wanted.

> n1, n2, n3, n4 = 5

n1 = n2 = n3 = n4 = 5

This works because the result of the assignment is the value which was
assigned. It's also not Ruby-specific. Probably even works in C.

> and do +=, -=, *=, etc with the same value
>
> n1, n2, n3, n4 += 5

This doesn't work because of the semantics of multiple assignment. See, your
first example:

n1, n2, n3, n4 = nil

That doesn't work because there's anything magical about nil. It works because
nil is the value when nothing is provided. It parses out to something like
this:

n1, n2, n3, n4 = nil, nil, nil, nil

And you can see this effect, too:

n1, n2, n3, n4 = 5

n1 will be 5, but n2, n3, and n4 won't be.

Now, with your semantics of doing a += there, shouldn't it be more like:

n1, n2, n3, n4 += 1, 2, 3, 4

> instead of
>
> n1 += 9; n2 += 9; n3 += 9; n4 += 9

Erm... I can't ever remember needing this. Not ever.

If you're trying to do it on an array, maybe something like:

0.upto(a.length-1) { |i| a[i] += 9 }

But unless I'm missing something -- and feel free to correct me with a real
example -- what you're trying to do really suggests that you want to refactor
your program a bit.

David A. Black

6/8/2008 6:56:00 AM

0

Hi --

On Sun, 8 Jun 2008, David Masover wrote:

> If you're trying to do it on an array, maybe something like:
>
> 0.upto(a.length-1) { |i| a[i] += 9 }

You could also use each_index there:

a.each_index {|i| a[i] += 9 }

or even:

a.map! {|e| e + 9 }


David

--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
ADVANCING WITH RAILS July 21-24 Edison, NJ
See http://www.r... for details and updates!

ProgramDragon

6/8/2008 7:03:00 AM

0

I think someone already asked this, but I want to confirm:

I am trying to write a program with a GUI, but I don't know what GUI
framework is the best.

I have heard that JRuby is a good option, but also heard that Swing was
a bad idea to use with JRuby.

I want to be able to write this program so that the end user can install
ruby, then run the program and it will start with no other installation
needed (like installing gems, etc, however I can do the gems in the program
on first run if it comes down to it).


I hope that makes sense, any ideas?


Sincerely,

Jayce Meade


David Masover

6/8/2008 7:24:00 AM

0

On Sunday 08 June 2008 02:03:23 ProgramDragon wrote:
> I think someone already asked this, but I want to confirm:

In the future, try to find the old thread and reply to it instead of starting
a new one.

> I am trying to write a program with a GUI, but I don't know what GUI
> framework is the best.

Nobody knows that yet, I think. That's why there's so many of them.

> I want to be able to write this program so that the end user can install
> ruby, then run the program and it will start with no other installation
> needed (like installing gems, etc, however I can do the gems in the program
> on first run if it comes down to it).

That's a completely separate problem from what GUI library to use. If you're
afraid to use libraries for this reason, SOLVE THIS PROBLEM NOW, and then
worry about GUI libraries. Simplifying your installation program is not an
excuse for NIH syndrome -- and just think how much time you'll have to polish
it if you find that half the program you wanted is already a gem.

If it's an open source project, or at least free-as-in-beer, you might
consider simply making it a gem. Then, all your users need to do is type:

gem install my_great_program

and all the dependent gems will be installed.

ProgramDragon

6/8/2008 7:39:00 AM

0

David,


Sorry, lol.

I am not afraid to use libraries, it's just that this is a bot
program for deviantART's chat network, and usually the people that want to
get them are not really that coherent in how to actually get one, so I'm
trying to make it as simple as I can. It's just a few ruby source files that
can be run with a batch file on Windows. It is open source, GNU GPL license.
The user just has to download and extract the program from a zip file,
however would that work with the Gems? It doesn't use a command prompt
window, the main file is a .rbw file.

One bot is installed by installing ruby, and then downloading,
extracting it, and then installing a gem for colors, and then running it
with a batch file. I would prefer to keep it simple as installing ruby,
download, extract, and run. I don't mind using gems or having to install
them, but the user that gets the program might.

--------------------------------------------------
From: "David Masover" <ninja@slaphack.com>
Sent: Sunday, June 08, 2008 12:23 AM
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Subject: Re: GUI library/framework?

> On Sunday 08 June 2008 02:03:23 ProgramDragon wrote:
>> I think someone already asked this, but I want to confirm:
>
> In the future, try to find the old thread and reply to it instead of
> starting
> a new one.
>
>> I am trying to write a program with a GUI, but I don't know what GUI
>> framework is the best.
>
> Nobody knows that yet, I think. That's why there's so many of them.
>
>> I want to be able to write this program so that the end user can
>> install
>> ruby, then run the program and it will start with no other installation
>> needed (like installing gems, etc, however I can do the gems in the
>> program
>> on first run if it comes down to it).
>
> That's a completely separate problem from what GUI library to use. If
> you're
> afraid to use libraries for this reason, SOLVE THIS PROBLEM NOW, and then
> worry about GUI libraries. Simplifying your installation program is not an
> excuse for NIH syndrome -- and just think how much time you'll have to
> polish
> it if you find that half the program you wanted is already a gem.
>
> If it's an open source project, or at least free-as-in-beer, you might
> consider simply making it a gem. Then, all your users need to do is type:
>
> gem install my_great_program
>
> and all the dependent gems will be installed.
>
>

Martin DeMello

6/8/2008 7:46:00 AM

0

On Sun, Jun 8, 2008 at 12:38 AM, ProgramDragon <programdragon@live.com> wrote:
> I am not afraid to use libraries, it's just that this is a bot program
> for deviantART's chat network, and usually the people that want to get them
> are not really that coherent in how to actually get one, so I'm trying to
> make it as simple as I can. It's just a few ruby source files that can be

Look up rubyscript2exe. It packages your program, all its libraries
and the ruby interpreter itself into a single executable.

martin

ProgramDragon

6/8/2008 7:51:00 AM

0

Martin,

Thanks, I had forgotten about that. Can it also load files from other
folders such as a Plugins folder? This program is supposed to be able to
have extensions added once it's completed. I am fairly new to Ruby, I've
only been working with it a few months. Sorry if I am asking stupid
questions, just trying to get advice from experts. =P

--------------------------------------------------
From: "Martin DeMello" <martindemello@gmail.com>
Sent: Sunday, June 08, 2008 12:45 AM
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Subject: Re: GUI library/framework?

> On Sun, Jun 8, 2008 at 12:38 AM, ProgramDragon <programdragon@live.com>
> wrote:
>> I am not afraid to use libraries, it's just that this is a bot
>> program
>> for deviantART's chat network, and usually the people that want to get
>> them
>> are not really that coherent in how to actually get one, so I'm trying to
>> make it as simple as I can. It's just a few ruby source files that can be
>
> Look up rubyscript2exe. It packages your program, all its libraries
> and the ruby interpreter itself into a single executable.
>
> martin
>
>

Martin DeMello

6/8/2008 8:32:00 AM

0

On Sun, Jun 8, 2008 at 12:51 AM, ProgramDragon <programdragon@live.com> wrote:
> Martin,
>
> Thanks, I had forgotten about that. Can it also load files from other
> folders such as a Plugins folder? This program is supposed to be able to
> have extensions added once it's completed. I am fairly new to Ruby, I've
> only been working with it a few months. Sorry if I am asking stupid
> questions, just trying to get advice from experts. =P

As long as it knows where to find your plugins folder, that shouldn't
be a problem. You won't be able to use relative paths, of course, but
something like a C:\yourapp\plugins should be fine. (Internally,
rubyscript2exe unpacks your app into a temp directory on the fly and
then executes it)

martin