Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # just "extend" this thing in your modules and/or "include" it if it is a class
- module Foo
- def foodef( name, attr_hash, method_name, method_code )
- attr.each { |k,v| instance_variable_set( k, v ) }
- method_name, method_code = foobuild(name)
- # Err, what exactly is the difference between eval and module_eval?
- eval(method_code, binding, __FILE__, __LINE__)
- method(method_name)
- end
- end
- module BuildCreationMethods
- extend Foo
- def def_assign(name)
- foodef( name, {"@bcm_polymorphic_assoc_name" => 'addressable'}, "#{name}_id=",
- <<-code_end
- def self.#{method_name}(arg)
- self.#{@bcm_polymorphic_assoc_name} = #{name.classify}.find_by_id arg
- end
- code_end
- )
- end
- end
Add Comment
Please, Sign In to add comment