Chad P. wrote:
Only we would never write that since the following does the same thing:
puts myarray
Well . . . true.
This is why I don’t teach programming.
Actually, I think there’s a difference in behavior
if you try them both.
Hal
Chad P. wrote:
Only we would never write that since the following does the same thing:
puts myarray
Well . . . true.
This is why I don’t teach programming.
Actually, I think there’s a difference in behavior
if you try them both.
Hal
James Edward G. II wrote:
(for example) and iterate over its contents using the each method to
Well . . . true.
This is why I don’t teach programming.Actually, I think there’s a difference in behavior
if you try them both.Other than the return value?
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?
Of course, I could pretend I was talking about the extraneous
‘do’ in ‘myarray.each do { |foo| puts foo }’ … but I wasm’t.
Hal
On Jan 2, 2006, at 2:08 PM, Hal F. wrote:
myarray.each do { |foo| puts foo }
Only we would never write that since the following does the same
thing:puts myarray
Well . . . true.
This is why I don’t teach programming.Actually, I think there’s a difference in behavior
if you try them both.
Other than the return value?
(1…10).to_a.each { |n| puts n }
1
2
3
4
5
6
7
8
9
10
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]puts (1…10).to_a
1
2
3
4
5
6
7
8
9
10
=> nil
James Edward G. II
Hal F. wrote:
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?
2006/1/2, Devin M. [email protected]:
Hal F. wrote:
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.
It’s true for hashes.
Hi –
On Tue, 3 Jan 2006, Hal F. wrote:
In particular, you could have an array called myarray
Well . . . true.
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
[email protected]
“Ruby for Rails”, from Manning Publications, coming April 2006!
Hal F. wrote:
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?
http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - 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
On Tue, Jan 03, 2006 at 06:22:56AM +0900, [email protected] wrote:
On Tue, 3 Jan 2006, Hal F. wrote:
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.
Maybe he was thinking of “print myarray”.
–
Chad P. [ CCD CopyWrite | http://ccd.apotheon.org ]
“A script is what you give the actors. A program
is what you give the audience.” - Larry Wall
Frank S. wrote:
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
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:
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
Frank S. wrote:
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
I’m also a java programmer who is learning Ruby. So far I installed the
one-click install version on my WinXP laptop, read the entire
“Programming Ruby” book included, and wrote one small app.
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.
Mike
Hi –
On Tue, 3 Jan 2006, Frank S. wrote:
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
[email protected]
“Ruby for Rails”, from Manning Publications, coming April 2006!
RevMike wrote:
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
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.
Devin M. wrote:
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…
RevMike wrote:
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
stijn wrote:
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs