Skip to content

Instantly share code, notes, and snippets.

@deivinsontejeda
Created October 10, 2013 14:24
Show Gist options
  • Save deivinsontejeda/6919226 to your computer and use it in GitHub Desktop.
Save deivinsontejeda/6919226 to your computer and use it in GitHub Desktop.
Constantize without ActiveSupport

Constatize a string without ActiveSupport (commonly come by default in rails) isn't friendly and in some case include AS is overkill. So, with this snipe you can constatize a String.

require 'net/http'
cls = "Net::HTTP".split('::').inject(Object) { |host,name| memo.const_get(name) }

# now you can use cls like normal constant
cls.new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment