I'm new to Ruby, and have basically NO previous coding experience in any
other language.
What I'm trying to do is create a program that will run from cmd prompt, and
let people type in words, or paragraphs etc., and then have those words etc.
reversed.
I'm new to Ruby, and have basically NO previous coding experience in any
other language.
What I'm trying to do is create a program that will run from cmd prompt, and
let people type in words, or paragraphs etc., and then have those words etc.
reversed.
Example:
This is my sentence => sentence my is This
Any help with this would be greatly appreciated!
Do you have `ri` installed on your system?
ri is a program which can provide help with Ruby's core classes and methods.
~> ruby -e 'ARGF.each { |l| puts l.split.reverse.join( " " ) }'
this is my sentence
sentence my is this
Its a great answer to your assignment if you can explain what all is happening. Good Luck!
Wes
···
On Jan 2, 2008, at 11:28 PM, 1up gfx wrote:
I'm new to Ruby, and have basically NO previous coding experience in any
other language.
What I'm trying to do is create a program that will run from cmd prompt, and
let people type in words, or paragraphs etc., and then have those words etc.
reversed.
What I'm trying to do is create a program that will run from cmd prompt, and
let people type in words, or paragraphs etc., and then have those words etc.
reversed.
I can't remember where exactly, but this is covered in at least one of
the basic tutorials (I know because I ran through them!). Do a google
search for "Ruby tutorial" and check some of those out.
If you can't find it after searching let me know and I'll try to track
it down.
I'm new to Ruby, and have basically NO previous coding experience in any
other language.
What I'm trying to do is create a program that will run from cmd prompt, and
let people type in words, or paragraphs etc., and then have those words etc.
reversed.
Example:
This is my sentence => sentence my is This
Any help with this would be greatly appreciated!
First attempt:
<macbook of doom:giles> [01-03 06:50] ~
! irb
gets.reverse
This is my sentence
=> "\necnetnes ym si sihT"
Second attempt:
<macbook of doom:giles> [01-03 06:51] ~
! irb
got = gets
This is my sentence
=> "This is my sentence\n"
got.chomp! # remove the newline
=> "This is my sentence"
gots = got.split # turn it into an array
=> ["This", "is", "my", "sentence"]
gots.reverse.join(" ") + "." # reverse the array, join it with
spaces, add a dot
=> "sentence my is This."
voila!
···
On 1/2/08, 1up gfx <jordan.rubytalk@gmail.com> wrote:
On Jan 3, 2008 12:48 AM, Wes Bailey <wes@verticalresponse.com> wrote:
On Jan 2, 2008, at 11:28 PM, 1up gfx wrote:
> I'm new to Ruby, and have basically NO previous coding experience in
> any
> other language.
>
> What I'm trying to do is create a program that will run from cmd
> prompt, and
> let people type in words, or paragraphs etc., and then have those
> words etc.
> reversed.
>
> Example:
>
> This is my sentence => sentence my is This
>
> Any help with this would be greatly appreciated!
~> ruby -e 'ARGF.each { |l| puts l.split.reverse.join( " " ) }'
this is my sentence
sentence my is this
Its a great answer to your assignment if you can explain what all is
happening. Good Luck!
Wes
Well, It's not really an assignment. I'm getting my cousin (who is a Java
programmer) to help me out with programming. He's basically just giving me
little tasks to do so that I become more familiar with programming. But,
since I don't really have any previous experience, I don't really know what
to do half of the time. Thanks for your replies though.
. . . and, aside from basic Ruby syntax, that might be everything you
need for the program.
···
On Thu, Jan 03, 2008 at 04:38:25PM +0900, Bill Kelly wrote:
From: "1up gfx" <jordan.rubytalk@gmail.com>
>
>I'm new to Ruby, and have basically NO previous coding experience in any
>other language.
>
>What I'm trying to do is create a program that will run from cmd prompt,
>and
>let people type in words, or paragraphs etc., and then have those words
>etc.
>reversed.
>
>Example:
>
>This is my sentence => sentence my is This
>
>Any help with this would be greatly appreciated!
Do you have `ri` installed on your system?
ri is a program which can provide help with Ruby's core
classes and methods.
Try (from your command prompt, not from IRB)
ri String#split
ri Array#reverse
ri Array#join
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Rudy Giuliani: "You have free speech so I can be heard."
You don't use irb for that. At the command prompt, that's the ruby command you give it.
$F = is an environmental variable that can receive split line input as an array
a = autosplit mode, basically takes the input and splits it out
n = pauses the command, like assuming a "while" command
e = the command
regards,
ch0wda
···
On Jan 3, 2008, at 2:46 PM, 1up gfx wrote:
On Jan 3, 2008 10:53 AM, Joel VanderWerf <vjoel@path.berkeley.edu> > wrote:
Wes Bailey wrote:
~> ruby -e 'ARGF.each { |l| puts l.split.reverse.join( " " ) }'
this is my sentence
sentence my is this
On Jan 3, 2008 12:58 PM, Joshua Schairbaum <joshua.schairbaum@gmail.com> wrote:
You don't use irb for that. At the command prompt, that's the ruby
command you give it.
$F = is an environmental variable that can receive split line input
as an array
a = autosplit mode, basically takes the input and splits it out
n = pauses the command, like assuming a "while" command
e = the command
regards,
ch0wda
On Jan 3, 2008, at 2:46 PM, 1up gfx wrote:
> On Jan 3, 2008 10:53 AM, Joel VanderWerf <vjoel@path.berkeley.edu> > > wrote:
>
>> Wes Bailey wrote:
>>> ~> ruby -e 'ARGF.each { |l| puts l.split.reverse.join( " " ) }'
>>> this is my sentence
>>> sentence my is this
>>
>> Golfing away...
>>
>> $ ruby -ane 'puts $F.reverse.join(" ")'
>> 1 2 3
>> 3 2 1
>>
>> --
>> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>>
>> It doesn't like your code... I keep on getting errors:
>
> irb(main):001:0> puts $F.reverse.join(" ")
> NoMethodError: undefined method `reverse' for nil:NilClass
> from (irb):1
> irb(main):002:0>
Alright, never mind, I got the program to work. Thank you for your help