New to Ruby and Programming

D

Devin Mullins

Hal said:
Well, I'm quite wrong. I thought that 'puts myarray' would print
on a single line with elements scrunched together. Maybe this
was true in the past?

No... that's perl, iirc. :)
Of course, I *could* pretend I was talking about the extraneous
'do' in 'myarray.each do { |foo| puts foo }' ... but I wasm't. ;)

wasm't?
 
D

dblack

Hi --

Well, I'm quite wrong. I thought that 'puts myarray' would print
on a single line with elements scrunched together. Maybe this
was true in the past?

I think what you're thinking of is array.to_s, which scrunches them
together. But puts array does a separate puts on each element.


David

--
David A. Black
(e-mail address removed)

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black
 
J

James Britt

Hal said:
Well, I'm quite wrong. I thought that 'puts myarray' would print
on a single line with elements scrunched together. Maybe this
was true in the past?

Maybe. It certainly struck me as counter-intuitive. I would think it
would print the results of myarry.to_s or myarry.to_str.

How (and why) did a call to an iterator get in there?

James
--

http://www.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools
 
C

Chad Perrin

I think what you're thinking of is array.to_s, which scrunches them
together. But puts array does a separate puts on each element.

Maybe he was thinking of "print myarray".
 
F

Frank Spychalski

Hi everybody,

I follow this list for some time but due to the volume I might have
missed it, if this was answered before...

I have another problem: I'm programming for some time (~20 years, if you
count the good old BASIC days), I've studied CS, I've used C/C++ (a
bit), Shell (some), Perl (some), PHP (some), Java (a lot) and a lot of
other languages. I think I understand most of the ruby language but I
fear I'm still using it in the wrong way. What I'm looking for, is a way
to learn 'the ruby way'. I'm thinking something like:

- Problem
- This is how you would have done it in another language
- Nice Ruby Solution

I have the pickaxe and the ruby on rails book and I'm reading both at
the moment. I looked through the sample chapter of 'The Ruby Way' but it
seemed more like a cookbook to me.

bye
Frank
 
D

Devin Mullins

Frank said:
What I'm looking for, is a way to learn 'the ruby way'. I'm thinking
something like:

- Problem
- This is how you would have done it in another language
- Nice Ruby Solution

I'm thinking the best way to do that is by posting examples (short,
repeatable code snippets for us to chew on). In general, it's usually
going to involve more functional constructs, and heavy use of blocks. :)
But that's not always the case. Usually, you'll get about Six Ruby Ways.

Devin
 
D

dblack

Hi --

Hi everybody,

I follow this list for some time but due to the volume I might have missed
it, if this was answered before...

I have another problem: I'm programming for some time (~20 years, if you
count the good old BASIC days), I've studied CS, I've used C/C++ (a bit),
Shell (some), Perl (some), PHP (some), Java (a lot) and a lot of other
languages. I think I understand most of the ruby language but I fear I'm
still using it in the wrong way. What I'm looking for, is a way to learn 'the
ruby way'. I'm thinking something like:

- Problem
- This is how you would have done it in another language
- Nice Ruby Solution

For me, part of the Ruby way is to skip the second of those three
steps :) Of course it can be interesting to compare implementations;
but from what I've seen, I don't think writing the code in another
language first is very useful as a way of learning Ruby. I'd
recommend going straight from problem to Ruby, and then working on the
Ruby.
I have the pickaxe and the ruby on rails book and I'm reading both
at the moment. I looked through the sample chapter of 'The Ruby Way'
but it seemed more like a cookbook to me.

Don't let that stop you from reading it, though. You'll learn a lot.
And a new edition is coming out, later this year.


David

--
David A. Black
(e-mail address removed)

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black
 
D

Devin Mullins

RevMike said:
In my opinion, if you know how to do something in one way, make it work.
then go back and refactor over and over again, trying different Ruby
constructs, until you are comfortable with what you are doing.
+1
 
S

stijn

wow, "the ruby way" may just have gotten ruby's equivalent of
help-me-make-my-program-more-"pythonic".

"deja-vu... a twitch in the matrix. It happens when they change
something."
hehe.
s.
 
R

Robert Klemme

stijn said:
wow, "the ruby way" may just have gotten ruby's equivalent of
help-me-make-my-program-more-"pythonic".

In the sense of the programming language or in the sense of the famous
british comedy group?
"deja-vu... a twitch in the matrix. It happens when they change
something."
hehe.
s.

itch <= twitch - what does this tell us?

robert
 
F

Frank Spychalski

Devin said:
I'm thinking the best way to do that is by posting examples (short,
repeatable code snippets for us to chew on). In general, it's usually
going to involve more functional constructs, and heavy use of
blocks. :) But that's not always the case. Usually, you'll get about
Six Ruby Ways.


The problem here is how to find the useful example. If I don't know that
something could be handled in a more elegant way, I don't know that this
could be a good example...
But I've gone back and refactored the app 3 times! And I have
another refactoring planned. The app has only two classes.

In my opinion, if you know how to do something in one way, make it
work. then go back and refactor over and over again, trying different
Ruby constructs, until you are comfortable with what you are doing.


I think that's a pretty good tip. I'm working on a small Ruby on Rails
application and every time I add new code I refactor a large portion of
old code because nearly every day I find new and easier ways of
doing something in Ruby...

bye
Frank
 

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

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top