Method For Making Methods: Easy Ruby Metaprogramming -


I have a bunch of helpful methods like this helpful

  def background " E9eaec "End Def Footer_link_golore" # 836448 "and  

I should see these methods in front of the scene, but I would love to help the assistant to be a bit more concise. What's the best way to turn the hash into modes (or something)?

  module MyHelper {: background => "#E9eaec" ,: footer_link_color = & gt; "# 836448"}. Do each. K, v | However, I do not think it is a good idea to trade this brevity for the readability of your first approach.  

> If you want to make it normal, you can add the following method to the module class:

  class mod methods_frame_hash (hash ) Hash.each do | K, v | Define_method (k) {v} End and End  

and then in your helper call methods_from_hash (: background = & gt; ...) .


Comments