Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a method provided by active_support outside of rails

How can I use a method that is defined in ActiveSupport module?

For example I wanted to use camelize method.

I tried this code, but it didn't work with undefined method error.

require 'active_support'
"foo_bar".camelize
like image 932
ironsand Avatar asked Oct 11 '25 15:10

ironsand


2 Answers

You can require just the part that supplies camelize, rather than all of Active Support:

require 'active_support/core_ext/string'
"camel_this".camelize => "CamelThis"
like image 86
Ryan Bigg Avatar answered Oct 14 '25 12:10

Ryan Bigg


You'll need to do require 'active_support/all'

This explains it...

http://guides.rubyonrails.org/active_support_core_extensions.html

like image 41
SteveTurczyn Avatar answered Oct 14 '25 12:10

SteveTurczyn