Class: Array

Inherits:
Object show all
Defined in:
lib/nyara/patches/array.rb,
lib/nyara/patches/blank.rb,
lib/nyara/patches/to_query.rb,
lib/nyara/patches/to_query.rb

Direct Known Subclasses

Nyara::View::Buffer

Instance Method Summary collapse

Instance Method Details

#sumObject


2
3
4
# File 'lib/nyara/patches/array.rb', line 2

def sum
  inject 0, :+
end

#to_paramObject

Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.


61
62
63
# File 'lib/nyara/patches/to_query.rb', line 61

def to_param
  collect { |e| e.to_param }.join '/'
end

#to_query(key) ⇒ Object

Converts an array into a string suitable for use as a URL query string, using the given +key+ as the param name.

['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"


104
105
106
107
# File 'lib/nyara/patches/to_query.rb', line 104

def to_query(key)
  prefix = "#{key}[]"
  collect { |value| value.to_query(prefix) }.join '&'
end