Mike
Mike

Reputation: 1580

Can't change string with Rails' String#camelize

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", "[email protected]", "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.

Upvotes: 1

Views: 461

Answers (2)

tompave
tompave

Reputation: 12427

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

Upvotes: 1

tiktak
tiktak

Reputation: 1811

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" 

Upvotes: 2

Related Questions