Last active
October 3, 2015 01:54
-
-
Save kwstannard/ab9be39465754ec41a85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### In file version | |
| klass = Class.new do | |
| def hi | |
| puts 'hello' | |
| end | |
| end | |
| name = __FILE__.slice(/\w*.rb$/).slice(/\w*/).camelcase | |
| Object.const_set(name, klass) | |
| ### Extracted version | |
| class Dryer | |
| def self.dry_class(file_name, &blk) | |
| klass = Class.new &blk | |
| name = __FILE__.slice(/\w*.rb$/).slice(/\w*/).camelcase | |
| Object.const_set(name, klass) | |
| end | |
| end | |
| Dryer.dry_class(__FILE__) do | |
| def herp | |
| puts 'hello' | |
| end | |
| end | |
| ### with inheritance | |
| class Dryer | |
| def self.dry_class(file_name, super_class, &blk) | |
| klass = Class.new(super_class, &blk) | |
| name = __FILE__.slice(/\w*.rb$/).slice(/\w*/).camelcase | |
| Object.const_set(name, klass) | |
| end | |
| end | |
| Dryer.dry_class(__FILE__, ActiveRecord::Base) do | |
| def herp | |
| puts 'hello' | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
latest crazy rails version: