Skip to content

Instantly share code, notes, and snippets.

@jhsu
Created November 19, 2009 13:29
Show Gist options
  • Select an option

  • Save jhsu/238765 to your computer and use it in GitHub Desktop.

Select an option

Save jhsu/238765 to your computer and use it in GitHub Desktop.
dynamically define easy partial helper methods
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