Ruby wishlist

J

jzakiya

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.
 
J

jzakiya

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]
=> 4
And you can't do this:
n1, n2, n3, n4 [+,-,*, etc]= [something]

Not sure what you want here.

way around.

Make sure you know the software.

Regards,
Rimantas
--http://rimantas.com/

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.
 
D

David Masover

$ 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 += 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.
 
D

David A. Black

Hi --

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

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


You could also use each_index there:

a.each_index {|i| a += 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.rubypal.com for details and updates!
 
P

ProgramDragon

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
 
D

David Masover

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.
 
P

ProgramDragon

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.
 
M

Martin DeMello

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
 
P

ProgramDragon

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
 
M

Martin DeMello

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
 
R

Robert Klemme

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.

way around.
Make sure you know the software.
!

Sorry for the confusion.

I want to set multiple variable to the same value:

n1, n2, n3, n4 = 5

Your variable naming indicates that you are probably using the wrong
tool: you rather want an Array of values vs. a number of variables. If
you do that, life becomes much easier:
and do +=, -=, *=, etc with the same value

n1, n2, n3, n4 += 5

ns.map! {|n| n + 5}

Kind regards

robert
 
J

jzakiya

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.
!

Sorry for the confusion.
I want to set multiple variable to the same value:
n1, n2, n3, n4 = 5

Your variable naming indicates that you are probably using the wrong
tool: you rather want an Array of values vs. a number of variables. If
you do that, life becomes much easier:
and do +=, -=, *=, etc with the same value
n1, n2, n3, n4 += 5

ns.map! {|n| n + 5}

Kind regards

robert

The names of the variables are not array values, they
are just different variable names, they could be any
names.

Remember, I would LIKE ruby to be able to do this.
It is my "whishlist". I know Ruby doesn't do it now,
but I would like it to be able to in the future. OK! :)

Peace

Jabari
 
C

Charles Oliver Nutter

ProgramDragon said:
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.

Not at all, Swing is a great idea. In fact, I'd go so far as to say
Swing is a lot better idea from JRuby than from Java.
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).

Monkeybars + Rawr can package up an application with all requirements
into a single executable .jar, .app, or .exe...awesome stuff.

- Charlie
 
A

AzimuthDragon

Is that so? Sounds cool. So I would be able to package my entire program
into a jar, .app or executable? I'm still not quite sure how to get it to
load things from outside the executable though, because the program isn't
installed into C:\Program Files. Most often it's extracted into a folder on
the user's desktop, so it needs to be able to generate a filepath. I have
been using Dir.getwd to generate a filepath to my main file, and then an
argument passed to the filepath method adds folder names onto the end, lol.
Would that still work, do you think? Here is my basic structure for the
program's directory, say it's in a folder called Ecko (doh). It would look
like this, if you outlined it.

/Ecko
Main.rbw
/System
config.rb
/Core
connection.class.rb
parse.class.rb
users.class.rb
extensions.class.rb
/Extensions
/Logs
/Images
/Screenshots
/Splash
/Data
/Docs
index.html


Basic layout, but that's what it would have to be able to go into if it was
an executable. Lol, I must sound like an idiot. xP
 
D

David Masover

The names of the variables are not array values, they
are just different variable names, they could be any
names.

Yes, we understand that. It's just probably better design for your program as
a whole to use an array here.

Can you give us more detail as to why you want this feature?
 
C

Charles Oliver Nutter

AzimuthDragon said:
Is that so? Sounds cool. So I would be able to package my entire program
into a jar, .app or executable? I'm still not quite sure how to get it
to load things from outside the executable though, because the program
isn't installed into C:\Program Files. Most often it's extracted into a
folder on the user's desktop, so it needs to be able to generate a
filepath. I have been using Dir.getwd to generate a filepath to my main
file, and then an argument passed to the filepath method adds folder
names onto the end, lol. Would that still work, do you think? Here is my
basic structure for the program's directory, say it's in a folder called
Ecko (doh). It would look like this, if you outlined it.

Yeah, that's the goal behind David Koontz's stuff in Monkeybars and
Rawr. I'm pretty sure you can provide your own structure, but he'd
probably know better. David, you out there?

Alternatively, try #monkeybars on freenode during the week.

- Charlie
 
R

Robert Klemme

2008/6/8 jzakiya said:
The names of the variables are not array values, they
are just different variable names, they could be any
names.

The names are irrelevant: the mere fact that you want to treat them
uniformly indicates that it is a bad idea to have them as separate
local variables and not in some type of collection.
Remember, I would LIKE ruby to be able to do this.
It is my "whishlist". I know Ruby doesn't do it now,
but I would like it to be able to in the future. OK! :)

The question is whether it is *reasonable* to build this into the
language. It does not make sense to put something into the language
to support a) an esoteric case or b) sub optimal design.

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top