Greetings :)

Hi, I'm Louis!
I like to code, but I don't do enough of it.

This blog is about trying my best to keep up with the ever evolving stream of technology.

Sunday, May 20, 2012

Ruby - dynamically create an object :)

Thought this was really cool :)

def create_object(class_name, *args)
  the_class = Object.const_get(class_name)
  the_object = the_class.send :new, *args if !args.empty?
  the_object = the_class.send :new if args.empty?
  
  return the_object
end

No comments:

Post a Comment