instance method
[]=
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
[]=( key, val )
Allows you to set or delete TMail header objects at will. Examples:
@mail = TMail::Mail.new @mail['to'].to_s # => 'mikel@test.com.au' @mail['to'] = 'mikel@elsewhere.org' @mail['to'].to_s # => 'mikel@elsewhere.org' @mail.encoded # => "To: mikel@elsewhere.org\r\n\r\n" @mail['to'] = nil @mail['to'].to_s # => nil @mail.encoded # => "\r\n"
Note: setting mail[] = nil actually deletes the header field in question from the object, it does not just set the value of the hash to nil
Parameters
-
keyreq -
valreq
Source
# File actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb, line 270
def []=( key, val )
dkey = key.downcase
if val.nil?
@header.delete dkey
return nil
end
case val
when String
header = new_hf(key, val)
when HeaderField
;
when Array
ALLOW_MULTIPLE.include? dkey or
raise ArgumentError, "#{key}: Header must not be multiple"
@header[dkey] = val
return val
else
header = new_hf(key, val.to_s)
end
if ALLOW_MULTIPLE.include? dkey
(@header[dkey] ||= []).push header
else
@header[dkey] = header
end
val
end
Defined in actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb line 270
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in TMail::Mail