class String
RJR
Ruby Core Extensions
Copyright © 2011-2014 Mohammed Morsi <mo@morsi.org> Licensed under the Apache License, Version 2.0
Public Instance Methods
to_class()
click to toggle source
Safely convert string to ruby class it represents
# File lib/rjr/core_ext.rb, line 8 def to_class split(/::/).inject(Object) do |p,c| case when c.empty? then p when p.constants.collect { |c| c.to_s }.include?(c) then p.const_get(c) else nil end end end