Converting string from snake_case to CamelCase in Ruby

前端 未结 10 1082
情书的邮戳
情书的邮戳 2020-11-30 19:57

I am trying to convert a name from snake case to camel case. Are there any built-in methods?

Eg: \"app_user\" to \"AppUser\"

(I hav

10条回答
  •  失恋的感觉
    2020-11-30 20:54

    How about this one?

    "hello_world".split('_').collect(&:capitalize).join #=> "HelloWorld"
    

    Found in the comments here: Classify a Ruby string

    See comment by Wayne Conrad

提交回复
热议问题