Skip to content

Commit

Permalink
Allow reply method to accept *args and &block
Browse files Browse the repository at this point in the history
  • Loading branch information
dball committed Nov 5, 2010
1 parent 0159e4b commit 4bc9529
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/mail/message.rb
Expand Up @@ -274,6 +274,18 @@ def reply(*args, &block)
if to
reply.from = self[:to].formatted.first.to_s
end

unless args.empty?
if args.flatten.first.respond_to?(:each_pair)
reply.send(:init_with_hash, args.flatten.first)
else
reply.send(:init_with_string, args.flatten[0].to_s.strip)
end
end

if block_given?
reply.instance_eval(&block)
end
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/mail/message_spec.rb
Expand Up @@ -1494,6 +1494,14 @@ def self.delivering_email(mail)
@mail.reply.from.should == ['raasdnil@gmail.com']
@mail.reply[:from].to_s.should == 'Mikel Lindsaar <raasdnil@gmail.com>'
end

it "should accept args" do
@mail.reply(:from => 'Donald Ball <donald.ball@gmail.com>').from.should == ['donald.ball@gmail.com']
end

it "should accept a block" do
@mail.reply { from('Donald Ball <donald.ball@gmail.com>') }.from.should == ['donald.ball@gmail.com']
end

end

Expand Down

0 comments on commit 4bc9529

Please sign in to comment.