1

Ruby is not my normal language, and I'm struggling to get the following to work.

I'm just working with an array.

irb(main):54232:0> contact_data
=> ["3521", "xxxxxxxx@xxxxxx.com", "ADA JONES SMITH"]

irb(main):54226:0> contact_data[2].split.first.to_s.camelize
=> "ADA"

Why? and how do I convert the string to CamelCase?

Thank you.

tompave
  • 11,952
  • 7
  • 37
  • 63
Mike
  • 1,532
  • 3
  • 21
  • 45

2 Answers2

2

Use downcase:

contact_data[2].split.first.to_s.downcase.camelize

Also titleize is useful method for your task.

2.1.2 :002 > "ADA".titleize
 => "Ada" 
tiktak
  • 1,801
  • 2
  • 26
  • 46
1

The problem is that contact_data[2].split.first is already completely upcase: "ADA", and the method String#camelize works on lowercase strings.

You should make it lowercase first:

contact_data[2].split.first.to_s.downcase.camelize
tompave
  • 11,952
  • 7
  • 37
  • 63