camelize

S

Sijo k g

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
 
J

Jiten Bhagat

Hi,

Try:

"re-open".titleize.gsub(' ', '-')

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

Cheers,
Jits
 
M

Marnen Laibow-Koser

Sijo said:
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,
 
P

Phrogz

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"
 
R

Ralph Shnelvar

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:


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"
 
M

Marnen Laibow-Koser

Ralph said:
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,
 
R

Ralph Shnelvar

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
 
M

Marnen Laibow-Koser

Ralph said:
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. :)

Best,
 
R

Ralph Shnelvar

Marnen,


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
 
M

Marnen Laibow-Koser

Ralph said:
Marnen,



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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top