Skip to content

Instantly share code, notes, and snippets.

@advorak
Last active August 29, 2015 13:58
Show Gist options
  • Save advorak/9980951 to your computer and use it in GitHub Desktop.
Save advorak/9980951 to your computer and use it in GitHub Desktop.
require 'active_support/all'
module Asdf
def self.new(connection_name, options)
classified_connection_name = connection_name.to_s.classify
self.class_eval <<-EOF
class #{classified_connection_name}
end
%w(aaa bbb ccc ddd).each do |letters|
class #{letters.classify} < #{classified_connection_name}
end
end
EOF
end
end
Asdf.new :connection_name, name: 'Andy'
__END__
# The result of the above code is as follows:
irb(main):017:0* Asdf.new :connection_name, name: 'Andy'
SyntaxError: (eval):5: syntax error, unexpected '<', expecting :: or '[' or '.'
class letters.classify < ConnectionName
^
(eval):7: syntax error, unexpected keyword_end, expecting end-of-input
from (irb):5:in `class_eval'
from (irb):5:in `new'
from (irb):17
from /home/advorak/.rbenv/versions/2.0.0-p247/bin/irb:12:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment