/ Published in: Other
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 # quick method on how to create dynamic methods or methods that share the same codebase method_names = [:dog, :cat, :man, :women] method_names.each do |attr_name| eval <<-END def #{attr_name} class << self ; attr_reader :#{attr_name} ; end # here is where you would write what you want your methods to do # simply reference the method with an @ sign @#{attr_name} = "#{attr_name}" end END end # the above code simply creates 4 methods named dog, cat, man, and women and outputs them as # strings
Comments
                    Subscribe to comments
                
                