Class: Array
- Defined in:
- lib/droiuby/support/to_query.rb,
lib/droiuby/support/object/blank.rb,
lib/droiuby/support/object/deep_dup.rb,
lib/droiuby/support/object/to_param.rb,
lib/droiuby/support/object/to_query.rb
Instance Method Summary collapse
-
#deep_dup ⇒ Object
Returns a deep copy of array.
-
#to_param ⇒ Object
Calls
to_paramon all its elements and joins the result with slashes. -
#to_query(key) ⇒ Object
Converts an array into a string suitable for use as a URL query string, using the given
keyas the param name.
Instance Method Details
#deep_dup ⇒ Object
Returns a deep copy of array.
array = [1, [2, 3]]
dup = array.deep_dup
dup[1][2] = 4
array[1][2] #=> nil
dup[1][2] #=> 4
27 28 29 |
# File 'lib/droiuby/support/object/deep_dup.rb', line 27 def deep_dup map { |it| it.deep_dup } end |
#to_param ⇒ Object
Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.
32 33 34 |
# File 'lib/droiuby/support/object/to_param.rb', line 32 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"
20 21 22 23 |
# File 'lib/droiuby/support/to_query.rb', line 20 def to_query(key) prefix = "#{key}[]" collect { |value| value.to_query(prefix) }.join '&' end |