Created
November 19, 2009 13:29
-
-
Save jhsu/238765 to your computer and use it in GitHub Desktop.
dynamically define easy partial helper methods
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
| helpers do | |
| def method_missing(method_name, *args, &block) | |
| method_str = method_name.to_s | |
| if method_str =~ /^_.+$/ | |
| options = {} | |
| options.merge!(args.first) unless args.empty? | |
| class_eval <<-RUBY | |
| def #{method_name.to_s}(options={}) | |
| haml :#{method_name}, :locals => args, :layout => false | |
| end | |
| RUBY | |
| send(method_name, options) | |
| else | |
| super | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment