Convert an array to a hash
class Array def to_h Hash[*self] end end
Use it like this:
['action', 'go', 'id', 6].to_h # => { 'action' => 'go', 'id' => 6 }
11390 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Danger http://6brand.com
class Array def to_h Hash[*self] end end
['action', 'go', 'id', 6].to_h # => { 'action' => 'go', 'id' => 6 }
class Array def total t = 0 self.each { |v| t += v } t end end
[1,2,2,3].total # => 8
# throw this in one of your controller helpers. # it works just like a combination of link_to_unless_current and link_to_remote def link_to_remote_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference, &block) if current_page?(options[:url]) if block_given? block.arity <= 1 ? yield(name) : yield(name, remote_function(options), html_options, *parameters_for_method_reference) else name end else link_to_function(name, remote_function(options), html_options) end end