Home
search
Collections
Sign in or create an account
×
Upload an optional image.
Medium site navigation
Upload an optional image.
João Neto
Coder from Fortaleza — Brazil
Follow
Most recommended
Instantiate classes in Ruby on Rails via String names
How to instantiate classes in Ruby on Rails via dynamic strings, like PHP $class = new $var()
The most simple way to dynamically instantiate a class from String in rails. On Rails do: mystring = “My::String::Name” #or mystring = “MyClassName” myclass = mystring.constantize.new Errors: ‘NotFoundClass’.constantize # => NameError: wrong constant name blargle More info at: http://apidock.com/rails/ActiveSupport/Inflector/constantize In Ruby without Rails, you can do with: classname = ‘Module::Class’ #or only Class classConst = Object.const_get( classname ) object = classConst.new
João Neto
1 min read
Latest
Solves Doctrine ORM Error with tables without Primary Key on MySQL when mapping the database.
This error: Table ____ has no primary key. Doctrine does not support reverse engineering from tables that don’t have a primary key.
João Neto
1 min read
Instantiate classes in Ruby on Rails via String names
How to instantiate classes in Ruby on Rails via dynamic strings, like PHP $class = new $var()
João Neto
1 min read
Welcome, Medium!
Hey! This is cool!
João Neto
1 min read
Recommended by João Neto
Solves Doctrine ORM Error with tables without Primary Key on MySQL when mapping the database.
This error: Table ____ has no primary key. Doctrine does not support reverse engineering from tables that don’t have a primary key.
João Neto
1 min read
Instantiate classes in Ruby on Rails via String names
How to instantiate classes in Ruby on Rails via dynamic strings, like PHP $class = new $var()
João Neto
1 min read
The Evolution of a Software Engineer
On Coming Full Circle
Sean Hickey
1 min read