End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
URI::MailTo.build
build(args)
lib/uri/mailto.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/uri/mailto.rb, line 85
def self.build(args)
tmp = Util.make_components_hash(self, args)
case tmp[:to]
when Array
tmp[:opaque] = tmp[:to].join(',')
when String
tmp[:opaque] = tmp[:to].dup
else
tmp[:opaque] = ''
end
if tmp[:headers]
query =
case tmp[:headers]
when Array
tmp[:headers].collect { |x|
if x.kind_of?(Array)
x[0] + '=' + x[1..-1].join
else
x.to_s
end
}.join('&')
when Hash
tmp[:headers].collect { |h,v|
h + '=' + v
}.join('&')
else
tmp[:headers].to_s
end
unless query.empty?
tmp[:opaque] << '?' << query
end
end
super(tmp)
end
Description
Creates a new URI::MailTo object from components, with syntax checking.
Components can be provided as an Array or Hash. If an Array is used, the components must be supplied as [to, headers].
If a Hash is used, the keys are the component names preceded by colons.
The headers can be supplied as a pre-encoded string, such as "subject=subscribe&cc=address", or as an Array of Arrays like [['subject', 'subscribe'], ['cc', 'address']].
Examples:
Example
require 'uri' m1 = URI::MailTo.build(['[email protected]', 'subject=Ruby']) m1.to_s # => "mailto:[email protected]?subject=Ruby" m2 = URI::MailTo.build(['[email protected]', [['Subject', 'Ruby'], ['Cc', '[email protected]']]]) m2.to_s # => "mailto:[email protected]?Subject=Ruby&[email protected]" m3 = URI::MailTo.build({:to => '[email protected]', :headers => [['subject', 'subscribe']]}) m3.to_s # => "mailto:[email protected]?subject=subscribe"