Camelize

Hi
I would like to get output as “Re-Open” for the input “re-open”
And I tried
“re-open”.camelize => “Re-open”

 Could you please tell how can I do this?

Thanks in advance
Sijo

Hi,

Try:

“re-open”.titleize.gsub(’ ', ‘-’)

(Assuming this is running in an environment that has Rails’
ActiveSupport library loaded).

Cheers,
Jits

Hi
Thanks .So no direct method is there.Right?

Sijo

Not that I am aware of.

Jits

On Nov 9, 1:43 am, Sijo k g [email protected] wrote:

Hi
I would like to get output as “Re-Open” for the input “re-open”
And I tried
“re-open”.camelize => “Re-open”

 Could you please tell how can I do this?

irb(main):001:0> s = “re-open”
=> “re-open”
irb(main):002:0> class String; def simple_titleize
irb(main):003:2> gsub(/\b[a-z]/i){ |x| x.upcase }
irb(main):004:2> end; end
=> nil
irb(main):005:0> s.simple_titleize
=> “Re-Open”

Phrogz,

What does the “i” do in
gsub(/\b[a-z]/i){ |x| x.upcase }
do?

I took it out and the pattern seemed to work.

Ralph

Monday, November 9, 2009, 10:10:07 PM, you wrote:

P> On Nov 9, 1:43 am, Sijo k g [email protected] wrote:

Hi
I would like to get output as “Re-Open” for the input “re-open”
And I tried
“re-open”.camelize => “Re-open”

 Could you please tell how can I do this?

irb(main):001:0>> s = “re-open”
=>> “re-open”
irb(main):002:0>> class String; def simple_titleize
irb(main):003:2>> gsub(/\b[a-z]/i){ |x| x.upcase }
irb(main):004:2>> end; end
=>> nil
irb(main):005:0>> s.simple_titleize
=>> “Re-Open”

Sijo k g wrote:

Hi
I would like to get output as “Re-Open” for the input “re-open”
And I tried
“re-open”.camelize => “Re-open”

 Could you please tell how can I do this?

You do know that “re-open” isn’t correct English (it should be
“reopen”), and that “Re-Open” is arguably incorrect capitalization,
right?

Thanks in advance
Sijo

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Ralph S. wrote:

Phrogz,

What does the “i” do in
gsub(/\b[a-z]/i){ |x| x.upcase }
do?

It makes the regex case-insensitive.

If you’re asking that kind of question, you need to go read Programming
Ruby.

I took it out and the pattern seemed to work.

Ralph

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Ralph S. wrote:

Marnen,

MLK> It makes the regex case-insensitive.

MLK> If you’re asking that kind of question, you need to go read
Programming
MLK> Ruby.

It’s on my desk and I am constantly reading it. I could not, and
still cannot, find where that is defined.

In the section on regular expressions, IIRC.

This is probably the 20th regular expression syntax that I have had to
learn. It gets old.

/i is the same in Perl, and in most other regex syntaxes like it.

Anyway, if you’re going to use a language, you need to learn the syntax
– no excuses. Sure it gets old, but so does using an out-of-date
language because you didn’t bother to learn a new one. :slight_smile:

Ralph

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen,

MLK> It makes the regex case-insensitive.

MLK> If you’re asking that kind of question, you need to go read
Programming
MLK> Ruby.

It’s on my desk and I am constantly reading it. I could not, and
still cannot, find where that is defined.

This is probably the 20th regular expression syntax that I have had to
learn. It gets old.

Ralph

Marnen,

It’s on my desk and I am constantly reading it. I could not, and
still cannot, find where that is defined.

MLK> In the section on regular expressions, IIRC.

It’s on page 320.

Just for the record … I did look before I posted the question … I
just couldn’t find it.

Ralph

Ralph S. wrote:

Marnen,

It’s on my desk and I am constantly reading it. I could not, and
still cannot, find where that is defined.

MLK> In the section on regular expressions, IIRC.

It’s on page 320.

Good to know. I use the Web edition, so I don’t have page numbers.

Just for the record … I did look before I posted the question … I
just couldn’t find it.

OK.

Ralph

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]