Class: String
Overview
RJR Ruby Core Extensions
Copyright © 2011-2014 Mohammed Morsi <[email protected]> Licensed under the Apache License, Version 2.0
Instance Method Summary collapse
-
#to_class ⇒ Object
Safely convert string to ruby class it represents.
Instance Method Details
#to_class ⇒ Object
Safely convert string to ruby class it represents
8 9 10 11 12 13 14 15 16 17 18 |
# 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 |