Guest User

Untitled

a guest
Feb 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1.  
  2. # just "extend" this thing in your modules and/or "include" it if it is a class
  3. module Foo
  4. def foodef( name, attr_hash, method_name, method_code )
  5. attr.each { |k,v| instance_variable_set( k, v ) }
  6. method_name, method_code = foobuild(name)
  7. # Err, what exactly is the difference between eval and module_eval?
  8. eval(method_code, binding, __FILE__, __LINE__)
  9. method(method_name)
  10. end
  11. end
  12.  
  13. module BuildCreationMethods
  14.  
  15. extend Foo
  16.  
  17. def def_assign(name)
  18. foodef( name, {"@bcm_polymorphic_assoc_name" => 'addressable'}, "#{name}_id=",
  19. <<-code_end
  20. def self.#{method_name}(arg)
  21. self.#{@bcm_polymorphic_assoc_name} = #{name.classify}.find_by_id arg
  22. end
  23. code_end
  24. )
  25. end
  26.  
  27. end
Add Comment
Please, Sign In to add comment