On Fri Jun 16, 2006 at 11:19:14 +1000, O Plameras wrote:
>O Plameras wrote:
>>Graham Smith wrote:
>>
>>>#!/usr/bin/ruby
>>>a=STDIN.readlines.sort_by {rand}
>>>puts a
>>
>>I'm new to Ruby. I understand Ruby was developed
>>to make the codes easy to read by Programmers (Humans)
>>more than to make it abiding by the machine logic.
>>This is not to say that the foregoing code is faulty
>>but to show an alternative way.
>>
>>So, this is how I'd code it.
>>
>>#!/usr/bin/env ruby
>>puts $stdin.readlines.sort_by {rand} unless $stdin.eof
>>
>>In human terms, it says 'put the lines that I got from standard input 
>>by sorting these lines randomly unless it is(excluding) the end-of-file'.
>>
>>O Plameras
>>
>>
>
>>Don't know ruby at all, so I'd like to understand the need for the
>>"unless $stdin.eof" part.
>
>"unless" means "exclude"
>"$stdin.eof" means "standard-input is end-of-line".
>
>So, it means "exclude when standard-input is end-of-line" as
>stated in last sentence of previous post. Tutorials I've been
>through use this.
>
>Matt has pointed out this is now redundant but no harm
>saying. No errors/warnings are generated by my Ruby interpreter.

Sorry, I'm still confused. I must be thick or something. I don't
understand ruby order of operation. Is this the logical equivilant of
(in pseudo ruby-python):

if not $stdin.eof
  puts $stdin.readlines.sort_by {rand}

Or is it something more subtle than that? Also I'm confused about
something in ruby is $stdin.eof a method, or a variable (or is there
no difference?)

Cheers,

Benno
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders

Reply via email to