9 Replies - 1962 Views - Last Post: 02 May 2016 - 05:35 AM Rate Topic: -----

#1 nick094  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 16

enumerate values

Posted 01 May 2016 - 01:28 PM

Hello fellas. Any kind of advice would be appreciated.
My goal is to Convert the message into numbers,like so: A = 1, B = 2... But i'm experiencing some problems,maybe because i already used scan/join. I'm new to ruby,so if this code doesn't make sense, feel free to comment. And in first line i wanted to
discard any non A to Z characters,uppercase all remaining letters,and split the message into five character groups.

text = "COde in Ruby,and enjoy!"
all_words = text.upcase.scan(/\w+/).join.scan(/.{4}/)



Is This A Good Question/Topic? 0
  • +

Replies To: enumerate values

#2 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,029
  • Joined: 12-May 09

Re: enumerate values

Posted 01 May 2016 - 01:56 PM

I'd be happy to help - can you provide some examples of the input you're sending, what you want out of it, and what you're actually seeing?
Was This Post Helpful? 0
  • +
  • -

#3 nick094  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 16

Re: enumerate values

Posted 01 May 2016 - 02:12 PM

View Postxclite, on 01 May 2016 - 01:56 PM, said:

I'd be happy to help - can you provide some examples of the input you're sending, what you want out of it, and what you're actually seeing?


I want to do this exercise: http://rubyquiz.com/quiz1.html ,but i don't know where even to start with the step 3,since every time i try splitting the variable into letters in order to numerate them, i get the error.
Was This Post Helpful? 0
  • +
  • -

#4 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,029
  • Joined: 12-May 09

Re: enumerate values

Posted 01 May 2016 - 02:32 PM

What is "the error"?
Was This Post Helpful? 0
  • +
  • -

#5 nick094  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 16

Re: enumerate values

Posted 01 May 2016 - 02:41 PM

View Postxclite, on 01 May 2016 - 02:32 PM, said:

What is "the error"?



"Undefined method".Should i def method and then just call it?
Thank you.
Was This Post Helpful? 0
  • +
  • -

#6 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,029
  • Joined: 12-May 09

Re: enumerate values

Posted 01 May 2016 - 03:03 PM

What's the full error? Ruby is usually pretty good at giving you a lot of information.
Was This Post Helpful? 0
  • +
  • -

#7 nick094  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 16

Re: enumerate values

Posted 02 May 2016 - 03:39 AM

View Postxclite, on 01 May 2016 - 03:03 PM, said:

What's the full error? Ruby is usually pretty good at giving you a lot of information.



I don't know how,but i finally did menage to split the letters. But i still don't have idea how to turn letters in numbers like A=1,B=2...
code so far:

text = "COde in Ruby,and enjoy!"
all_words = text.upcase.scan(/\w+/).join.scan(/.{4}/)
all_words.scan(/\w/)



Was This Post Helpful? 0
  • +
  • -

#8 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,029
  • Joined: 12-May 09

Re: enumerate values

Posted 02 May 2016 - 04:47 AM

Have you done a ruby tutorial? Mapping something to something else can be done in quite a few ways, one of which you'd be able to do with a "Hash" object.
Was This Post Helpful? 0
  • +
  • -

#9 nick094  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 16

Re: enumerate values

Posted 02 May 2016 - 05:03 AM

View Postxclite, on 02 May 2016 - 04:47 AM, said:

Have you done a ruby tutorial? Mapping something to something else can be done in quite a few ways, one of which you'd be able to do with a "Hash" object.



I did some tutorial on ruby that covers mapping but it wasn't explained in the best way,and i'm currently reading "Beginning Ruby:from novice to professional",and i'm quite satisfied with the way everything is covered. I just couldn't find what i needed,so i posted a question here. Thank you.
Was This Post Helpful? 0
  • +
  • -

#10 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,029
  • Joined: 12-May 09

Re: enumerate values

Posted 02 May 2016 - 05:35 AM

So, there are two ways to turn letters to numbers that are pretty straightforward. One, store a mapping of letter to number in a hash object (you should be able to figure this out if what you're reading is actually satisfactory), and query that with each letter you received.

Another is to use something like this and do some subtraction to get the number you want.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1